Skip to content

Sevendays-Digital/filament-nested-resources

Repository files navigation

Helpers to work with nested resources

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.

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •