sevendays-digital / filament-nested-resources
Helpers to work with nested resources
Fund package maintenance!
Sevendays-Digital
Installs: 2 102
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 1
Forks: 8
Open Issues: 14
Requires
- php: ^8.1
- filament/filament: ^2.0
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- pestphp/pest-plugin-livewire: ^1.0
- pestphp/pest-plugin-parallel: ^0.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-10-09 05:08:01 UTC
README
This package adds support for nested resources in Filament.
It provides the base classes and column to provide the nested structure.
It currently is not that configurable and you need to follow naming conventions usually used by Laravel.
Demo:
Screen.Recording.2023-04-07.at.13.14.05.mov
Installation
You can install the package via composer:
composer require sevendays-digital/filament-nested-resources
Usage
Currently you need to do a couple of changes to make this work. But you start of by creating a filament resource (The parent resource should already exist at this point. The resource we are changing is the child one).
Once you have that, you will need to change the Filament/Resources/ChildModelResource.php
to the NestedResource
.
use SevendaysDigital\FilamentNestedResources\Columns\ChildResourceLink; use SevendaysDigital\FilamentNestedResources\NestedResource; class ChildModelResource extends NestedResource { public static function getParent(): string { return ParentModelResource::class; } }
Then for each of the resource pages, you need to add the trait:
use SevendaysDigital\FilamentNestedResources\ResourcePages\NestedPage;
Finally, on your ParentModelResource
you can add the column to provide the links:
public static function table(Table $table): Table { return $table ->columns([ ChildResourceLink::make(ChildModelResource::class), ]); }
Accessing the parent
When you need the parent in livewire context such as the form, you can add the second argument to your form method:
public static function form(Form $form, ?Event $parent = null): Form;
Where Event
is the model that should be the parent.
Sidebar
By default when in a "context" the sidebar will register the menu item for that resource.
So if you are inside a Project which has documents, the sidebar will show documents when you are on a project or deeper level.
If you do not want this, you can set shouldRegisterNavigationWhenInContext
to false in the child resource.
Notes
You cannot use a child resource for multiple parents, however, you can can have multiple resources pointing to the same model.
Just make sure you set a custom slug for the resources so that it builds unique routes.
https://filamentphp.com/docs/2.x/admin/resources/getting-started#customizing-the-url-slug
Testing
There's none :).
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.