You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
User can have personal permissions and group-based permissions. Currently, if I am not missing something, there is no function to list all of them together.
You can use $user->can() to check on a single permission out of all or use $user->getPermissions() to get personal permissions only. I suggest to add a function $user->getAllPermissions() to get them all.
I helped myself with a little helper function like so:
/** * Gets group based and user based permissions for a given user ID. * * @param int $id - User ID to check * @return array - Array of Shield permissions */functiongetAllUserPermissions($id = null)
{
if (!$id) thrownew \RuntimeException('Users must be created before getting their permissions.');
$user = model(UserModel::class)->find($id);
//// Get personal permissions//$permissions = $user->getPermissions();
//// Add group based permissions//$groups = $user->getGroups();
foreach ($groupsas$g) {
$groupPermissions = config('AuthGroups')->matrix[$g];
foreach ($groupPermissionsas$gp) {
$permissions[] = $gp;
}
}
return$permissions;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
User can have personal permissions and group-based permissions. Currently, if I am not missing something, there is no function to list all of them together.
You can use
$user->can()
to check on a single permission out of all or use$user->getPermissions()
to get personal permissions only. I suggest to add a function$user->getAllPermissions()
to get them all.I helped myself with a little helper function like so:
Beta Was this translation helpful? Give feedback.
All reactions