I've a role system with the following roles:
-Super Admin
-Admin
-Author
-User
In blade (and other places) I want to make sure that user is an admin (either has Admin role or Super Admin role).. How can I use @role('admin') in blade to also include 'Super Admin' since they are admins after all?
Hi @hollycoder
At the present time, with this package, roles don't "extend" other roles.
Here are 3 options to consider:
Check for multiple roles: @hasanyrole('Admin|Super Admin')
"Extend" the roles by granting all permissions for Admin to Super Admin as well (yes, that means a small amount of duplication in assigned permissions), and then build your application around @can rules instead of ever checking for roles at all.
(Using can and avoiding role-checking wherever possible is generally a best-practice.)
Grant Super Admin "everything" permission. This requires using can everywhere, and then setting up a Gate before hook as described in this Wiki article: https://docs.spatie.be/laravel-permission/v2/basic-usage/super-admin/
This 3rd approach is what I embrace in most of my projects.
Does that help?
Most helpful comment
Hi @hollycoder
At the present time, with this package, roles don't "extend" other roles.
Here are 3 options to consider:
Check for multiple roles:
@hasanyrole('Admin|Super Admin')"Extend" the roles by granting all permissions for Admin to Super Admin as well (yes, that means a small amount of duplication in assigned permissions), and then build your application around
@canrules instead of ever checking forroles at all.(Using
canand avoiding role-checking wherever possible is generally a best-practice.)Grant Super Admin "everything" permission. This requires using
caneverywhere, and then setting up aGatebeforehook as described in this Wiki article: https://docs.spatie.be/laravel-permission/v2/basic-usage/super-admin/This 3rd approach is what I embrace in most of my projects.
Does that help?