roles
roles copied to clipboard
Role hasPermission?
How to go about checking if a given role has specified permission? For example: $role = Role:find(1); if ($role->hasPermission(3)) { echo "role with id 1 has permission with id 3"; }
Thanks in advance.
You can do this using default eloquent functions. Retrieve all permissions by doing:
$role = Role::find(1);
$permissions = $role->permissions;
You can use the find method to see if it exists:
if($permissions->find(26) !== null) {
//has the permission
}
Thank you, that works.