Based on a permission, how can a user view only their own records?
If the permission is anebaled in filament shield, then you can see all records, but if its disabled then youcan only see your own records.
12 Replies
I tried using the permissions from the policies, but when diasbling "view any", I dont see anything
in your ModelResource, getEloquentQuery function do this:
public static function getEloquentQuery(): Builder
{
$user = auth()->user();
$query = parent::getEloquentQuery();
if ($user->your_permission_condition) {
return $query->where());
}
return $query;
}
Im really frustrated
SOmetimes the permissions works, and other times it doesntg
I do not understand why
The resource is called TimeRegistrationResource
For example, I am on admin_user account; it works, I switch to a filament_user account; it works, I switch back to admin_user account, and it doesnt work anymore
using dd($user->can('view_all_registrations_time')), no matter if the permission is enabled or disabled on filament shield page, it always returns false,
And the resource implements " HasShieldPermissions "
@Dennis Koch ?
I don’t know. Is the permission set on the database?
Uhm, not afaik. Its done automatically by shield
Yes I know. I meant: "Check the database whether it's set correctly"
Ahh I see
I just checked, and it hasnt
You need to debug where it goes wrong then.
Its oke, I fixed it!
What was the issue?
I added "::registration" after the permission. I ran php artisan shield:generate --all, and then I could see the permission in the permissions table