I'm designing a web app where there are several user roles and permissions so I try out laravel-permission which looks great and I can create roles and permissions according to the guide.
I created user roles: super-admin, admin, office-admin, inspector, user.
super-admin can grant admin role,
admin can grant office-admin role and
office-admin can grant inspector role.
And I created grant-user permission and UserPolicy which has grant() method that looks like this.
public function grant(User $user, User $model, string $role)
{
// super-admin can grant admin
if ($user->isSuperAdmin() && $role === User::ADMIN) {
return true;
}
// admin can grant office-admin
if ($user->isAdmin() && $role === User::OFFICE_ADMIN) {
return true;
}
// office-admin can grant inspector in the office
if (
$user->isOfficeAdmin() && $role === User::INSPECTOR &&
$user->office->id === $model->office->id
) {
return true;
}
}
But then I do not use permissions table at all, just roles and UserPolicy. So I think I did something wrong here. What would be the use for permissions table in this case? What should be changed to use it correctly?