On ListResource.php - How to show only the resources which belong to the current user?
I am using filament's plugin for Spatie Laravel Permissions, and everything works just fine except this thing. I dont want to hide the whole resource from the navigation bar so
viewAny()
along with $post->user_id === auth()->user()
won't fit here..10 Replies
You should have field like user_id in the db and modify the query
thanks @krekas!
@prowler spatie permission package is more for resource permission. What you're talking about is record permission which is called multi-tenancy, so yes as @krekas said filter it by user_id on resource query level or in Eloquent with global scopes.
I think so
Not sure im talking about multi-tenancy in Filament's terms.
I simply have 3 different Roles for users (Client, Editor and Super Admin) using spatie's package which lets me fine-grain their permissions per resource (a requirement i have). Each role may or may not be visible to different resources (or in some cases, to resource's specific fields).
Each user associated with a role and for example, when a
Client
logs in - I simply want them to see their data only. Each user belongs to 1 tenant only, whileFilament's tenancy system implies that the user belongs to many tenants (organizations, teams, companies, etc.) and may switch between them.
if you want user to see only his own records you must add some field where you would attach usually users id. this field usually is
user_id
oh yeah, ofc. i already have this field.
what i was missing is the query modification thingy, which u answered
yes. this is what you need
you could call it a tenancy in a way
Yeah the term tenancy has so many meanings and cases. In this case, user is a tenant.
Thank u all!
@PovilasKorop - btw, a big fan of your stuff! keep up the good work