filament icon indicating copy to clipboard operation
filament copied to clipboard

Nested resources

Open zepfietje opened this issue 2 years ago • 10 comments

zepfietje avatar Jul 21 '23 14:07 zepfietje

This would be amazing.

Perhaps we could add a $parentResourceClass to the Resource objects and change the routing accordingly. I am guessing this should only work with belongsTo relations.

Then make the parent available via the getParent() method and $parent property just like we can access the getRecord() and $record.

falko100 avatar Jul 30 '23 07:07 falko100

@falko100 I don't think we should support only the BelongsTo relationship. I'm de suggester of this feature and I don't think this should work "automagically" behind the scenes. I think we need to let users customize their parents using some trait or extending a ParentResource or ChildrenResource

I have a couple of use cases for this, gonna give some examples to help the team with the brainstorming of this feature:

Blogging

  • User can create many blogs /app/blogs
  • User can list blog posts /app/blogs/{1}/posts
  • User can view blog post /app/blogs/{1}/posts/{1}
  • User can list blog categories, but categories may belong to multiple blogs /app/blogs/1/categories
  • User can list posts inside a category /app/blogs/1/categories/1/posts

Calendar events

  • User can create many calendars /app/{calendars}
  • User can list calendar events /app/calendars/{1}/events
  • User can view calendar event /app/calendars/{1}/events/{1}

GitHub-like interface

  • User can create an org /{filamentphp}
  • User can create repositories inside orgs /{filamentphp}/repositories/{filament}
  • User can list issues of a repository /{filamentphp}/repositories/{filament}/issues
  • User can view files of a PR /{filamentphp}/repositories/{filament}/pulls/{1}/files/{tables.blade.php}

I've already had this setup working with filament, but the only issue is breadcrumbs and route parameter resolving everything else is already working.

Basically, we only need to inform a resource of its parent (for route param resolving) and add /{parentSlug}/{parentRecord} to the children's resource URLs.

saade avatar Jul 30 '23 19:07 saade

@saade I get your point. I don't see a particular use-case for having the ManyToMany nested (the categories-posts relation) as they are not hierarchical, but if the team thinks that it will work, I am all for it.

I wouldn't mind helping out on the PR.

falko100 avatar Aug 02 '23 10:08 falko100

no plz dont depending

TheNamelessKing1017 avatar Aug 04 '23 12:08 TheNamelessKing1017

Great to see this on the roadmap. I have the need for this in many of the applications I build.

Looking forward to where this goes! 🚀

chrisreedio avatar Aug 09 '23 23:08 chrisreedio

I have sub-resources working with a reusable trait - coupled with the new SubNavigation Feature - I think it's a good start. Probably needs a few changes, but if anyone is looking for ideas: https://gist.github.com/nicko170/7348812b1240f2eb196fd22ece1fe977

nicko170 avatar Sep 27 '23 13:09 nicko170

https://laraveldaily.com/post/filament-v3-nested-resources-trait-pages

krekas avatar Oct 12 '23 09:10 krekas

@krekas nice work! Just made some small refactors to make the code a bit cleaner =)

https://github.com/LaravelDaily/filament-nested-resources/pull/1

saade avatar Oct 12 '23 14:10 saade

@saade not my work. Just sharing :)

krekas avatar Oct 12 '23 14:10 krekas

There is this package also https://github.com/Sevendays-Digital/filament-nested-resources, but I don't know if it works with V3 or with spatie-translatable

Ahmant avatar Nov 21 '23 15:11 Ahmant