Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete
paste.mozilla.org allows you to share code snippets and notes with others. These pastes require a link to be viewed; they are not private. Anyone with the link is able to see the paste and also delete it.


Please refrain from sharing personal or sensitive information on this website to avoid it being viewed by other parties.

  1. /****************************************************
  2. * PageDisplayController (for rendering frontend)
  3. */
  4. <?php
  5. namespace App\Http\Controllers\Web;
  6. use App\Repositories\PageRepository;
  7. use Inertia\Inertia;
  8. use Inertia\Response;
  9. use CwsDigital\TwillMetadata\Traits\SetsMetadata;
  10. class PageDisplayController
  11. {
  12. use SetsMetadata;
  13. public function index(string $slug, PageRepository $pageRepository): Response
  14. {
  15. $page = $pageRepository->forSlug($slug);
  16. abort_if(!$page, 404);
  17. $blocks = $page->blocks->toArray();
  18. $this->setMetadata($page);
  19. return Inertia::render("EnglishEditing", ['blocks' => $blocks]);
  20. }
  21. }
  22. /******************************
  23. * Controller
  24. */
  25. <?php
  26. namespace App\Http\Controllers\Twill;
  27. use A17\Twill\Models\Contracts\TwillModelContract;
  28. use A17\Twill\Services\Forms\Fields\Input;
  29. use A17\Twill\Services\Forms\Fields\BlockEditor;
  30. use A17\Twill\Services\Forms\Form;
  31. use A17\Twill\Http\Controllers\Admin\ModuleController as BaseModuleController;
  32. class PageController extends BaseModuleController
  33. {
  34. protected $moduleName = 'pages';
  35. public function getForm(TwillModelContract $model): Form
  36. {
  37. $form = parent::getForm($model);
  38. $form->add(
  39. Input::make()->name('description')->label('Description')
  40. );
  41. $form->add(
  42. BlockEditor::make()
  43. );
  44. $form->addFieldset(
  45. \A17\Twill\Services\Forms\Fieldset::make()
  46. ->title(trans('twill-metadata::form.titles.fieldset'))
  47. ->id('metadata')
  48. ->fields([
  49. \A17\Twill\Services\Forms\BladePartial::make()->view('twill-metadata::includes.metadata-fields')
  50. ->withAdditionalParams([
  51. 'metadata_card_type_options' => config('metadata.card_type_options'),
  52. 'metadata_og_type_options' => config('metadata.opengraph_type_options'),
  53. ]),
  54. ])
  55. );
  56. return $form;
  57. }
  58. }
  59. /*****************************************************
  60. * Model
  61. */
  62. <?php
  63. namespace App\Models;
  64. use A17\Twill\Models\Behaviors\HasBlocks;
  65. use A17\Twill\Models\Behaviors\HasSlug;
  66. use A17\Twill\Models\Behaviors\HasRevisions;
  67. use A17\Twill\Models\Behaviors\HasPosition;
  68. use A17\Twill\Models\Behaviors\Sortable;
  69. use A17\Twill\Models\Model;
  70. use A17\Twill\Models\Behaviors\HasMedias;
  71. use CwsDigital\TwillMetadata\Models\Behaviours\HasMetadata;
  72. class Page extends Model implements Sortable
  73. {
  74. use HasBlocks, HasSlug, HasRevisions, HasPosition, HasMetadata, HasMedias;
  75. public \Illuminate\Contracts\Foundation\Application|
  76. array|
  77. \Illuminate\Config\Repository|
  78. \Illuminate\Foundation\Application
  79. $metadataFallbacks = [];
  80. public $mediasParams = [
  81. 'cover' => [
  82. 'default' => [
  83. [
  84. 'name' => 'default',
  85. 'ratio' => 16 / 9,
  86. ],
  87. ],
  88. ],
  89. ];
  90. protected $fillable = [
  91. 'published',
  92. 'title',
  93. 'description',
  94. 'position',
  95. ];
  96. public $slugAttributes = [
  97. 'title',
  98. ];
  99. }
  100. /**********************************
  101. * Repository
  102. */
  103. <?php
  104. namespace App\Repositories;
  105. use A17\Twill\Repositories\Behaviors\HandleBlocks;
  106. use A17\Twill\Repositories\Behaviors\HandleSlugs;
  107. use A17\Twill\Repositories\Behaviors\HandleRevisions;
  108. use A17\Twill\Repositories\Behaviors\HandleMedias;
  109. use A17\Twill\Repositories\ModuleRepository;
  110. use App\Models\Page;
  111. use CwsDigital\TwillMetadata\Repositories\Behaviours\HandleMetadata;
  112. class PageRepository extends ModuleRepository
  113. {
  114. use HandleBlocks, HandleSlugs, HandleMedias, HandleRevisions, HandleMetadata;
  115. public function __construct(Page $model)
  116. {
  117. $this->model = $model;
  118. }
  119. }

Edit this Snippet