There has been multiple requests for this (#128, #161) and they didn't result in an implementation because this feature was thought to not be needed for most users.
However, I think it is pretty common to have a role inheritance, as previous suggestions explained: an administrator would inherit lower roles. This would avoid having to manually apply each permission to every role, or adding roles like moderator and user to administrator.
I know you guys would like to keep things as simple as possible, but this is the permission package and I think this feature would be really appreciated. Thank you 馃槉
+1
you can assign multiple Roles to the same user
@dennis-git sure, but it doesn't solve the issue. At best, it's a workaround.
@hawezo I am agree with you, I really need this feature in my project
I would need that feature as well.
+1
+1
+1
+1
+1
1
+1
+1
What type of inheritance are you needed to implement?
(simple or multiple)
In my case, if a role like administrator can inherit a moderator role which would inherit a user role, for instance, it would be enough.
If by multiple inheritance you mean that a role would be able to inherit multiple other roles, I don't personally need it, but I'm sure that it'd be a useful feature.
While not entirely the same as "group inheritance" discussed here, it's worth looking at #1381, released in 3.9.0.
I mention it here because I know some people think about "inheritance" the same as the sub-levels offered by this "wildcard" strategy.
Technically you could implement this in your own application during setup of the roles and permissions (see below). Granted, it is not done at runtime, but the problem with doing this at runtime is that it will require another relationship to be implemented. For every relationship implemented, another performance hit has to be taken.
// First Option: Existing Role
$moderator = Role::create([ 'name' => 'Moderator' ]);
$moderator->givePermissionTo(
Role::findByName('User')->permissions->merge([
Permission::findByName('post.edit'),
Permission::findByName('post.delete'),
])
);
// Second Option: Create them all at once
$userPermissions = collect([
'post.create',
]);
$moderatorPermissions = $userPermissions->merge([
'post.edit',
'post.delete',
]);
$user = Role::create([ 'name' => 'User' ]);
$user->givePermissionTo( $userPermissions );
$moderator = Role::create([ 'name' => 'Moderator' ]);
$moderator->givePermissionTo( $moderatorPermissions );
Most helpful comment
I would need that feature as well.