Coder Social home page Coder Social logo

filament-nested-resources's Introduction

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.

filament-nested-resources's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar haringsrob avatar mstfkhazaal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.