based on roles only view index and create
Hello! i only want to display the create for the user role . The admin will have acces to index,edit and create
Does anyone know how to do this?
5 Replies
Use policy's
You can just add it in the resource just as i wanted to
but i don't know how to do the index page
I thought of another way just create another page where we can create the resource. So just did the canViewAny on admin in the resource
Can you share some code? I didn’t understand how to integrate policies, for example i need only to have 3 user roles and each ones can view or crud some resources
public static function canView(): bool
{
return auth()->user()->hasRole('admin');
}
for example
you can also do canEdit and canCreate
It's super-simple if you do it via a Laravel model Policy. Similar logic as Quin wrote, but defined in the Policy. That way the access control applies anywhere you use the model, because Filament Resources automatically use the Policy.