F
Filamentβ€’4mo ago
Wrax

Resource Scoping Best Practice

I have built a decent CRUD experience in the context of an admin user but I am unsure of what the best practice is for scoping resources to a user context. For example, admin can interact with all records while I want a user to interact only with their own records e.g Posts vs My Posts. I am currently thinking of creating new separate user specific resources based on the original admin resource Is this sensible or have I got this wrong? Guidance appreciated πŸ™‚
Solution:
As always it very much depends. If the resources are pretty much the same you can use getEloquentQuery() on the Resource to scope the data to the current user (if they aren't admin). If you plan to make more changes, I'd split them into separate panels. That will lead to less authorization issues since you might forget to hide critical info or actions for non-admins....
Jump to solution
2 Replies
Solution
Dennis Koch
Dennis Kochβ€’4mo ago
As always it very much depends. If the resources are pretty much the same you can use getEloquentQuery() on the Resource to scope the data to the current user (if they aren't admin). If you plan to make more changes, I'd split them into separate panels. That will lead to less authorization issues since you might forget to hide critical info or actions for non-admins.
Wrax
WraxOPβ€’4mo ago
Thanks Dennis, I just created a seperate panel while waiting for a response to this post. Glad to know that I am on the right track. For anyone with a similar question that finds this post later here are some relevant resources that I have used to move forward: Creating new panels: https://www.youtube.com/watch?v=gJacrxk7v4E https://filamentphp.com/docs/3.x/panels/configuration#creating-a-new-panel Scoping a resource query: https://filamentphp.com/docs/3.x/panels/resources/getting-started#customizing-the-resource-eloquent-query
Laravel Daily
YouTube
NEW in Filament 3: Multiple Panels
In the new version, you can create separate panels for different users. Read more in the docs: https://filamentphp.com/docs/3.x/panels/configuration My full course: "Filament 3 From Scratch: Practical Course" https://laraveldaily.com/course/filament-3 - - - - - Support the channel by checking out my products: - My Laravel courses: https://lara...
Want results from more Discord servers?
Add your server