Advanced Guides
Extending Pages
Autoload Pages can be "extended" through other Laravel Models so that they get the same benefits a default Page gets, such as routing, caching, SEO, etc.
Example
A popular example of extending a Page are Product pages. This is useful if wish to have a separate Product Model but also want that Product to have a publicly-accessible page without building your own Product router or caching.
Relationship Trait
First, create a new Product Model in your Laravel application however you wish. Next, add the following Trait to your new Model:
1use \Mergeloop\Autoload\Support\HasAutoloadPage;
This will add the Page relationship and custom Accessors for fetching Page details. You can use these like so;
1$product->page_name2// same as3$product->page->name
You may also use queries for resolving if a Model has an Active page using ->pageActive()
:
1\App\Models\Product::query()2 ->pageActive()3 ->firstOrFail();
Configuration
Next, add that Model to the page_filament_relationships
array in the config/autoload.php
configuration file:
1'page_filament_relationships' => [2 \App\Models\Product::class => 'name',3],
The value of "name" is what will be used to display the relationship.