Laravel-permission: Question: Can I 'extend' another role?

Created on 9 Jun 2018  路  1Comment  路  Source: spatie/laravel-permission

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?

question

Most helpful comment

Hi @hollycoder

At the present time, with this package, roles don't "extend" other roles.

Here are 3 options to consider:

  1. Check for multiple roles: @hasanyrole('Admin|Super Admin')

  2. "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.)

  3. 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?

>All comments

Hi @hollycoder

At the present time, with this package, roles don't "extend" other roles.

Here are 3 options to consider:

  1. Check for multiple roles: @hasanyrole('Admin|Super Admin')

  2. "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.)

  3. 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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

feliperoan picture feliperoan  路  3Comments

hosseinnedaei picture hosseinnedaei  路  3Comments

MichalKrakow picture MichalKrakow  路  4Comments

holymp2006 picture holymp2006  路  4Comments

younus93 picture younus93  路  4Comments