-
Notifications
You must be signed in to change notification settings - Fork 0
Role Permissions
Carlos G. Camacho O edited this page May 15, 2018
·
1 revision
The bundled Role
model has easy to use methods to manage and assign permissions.
can($permission)
getPermissions()
assignPermission($permissionId)
revokePermission($permissionId)
revokeAllPermissions()
syncPermissions([$permissionIds])
Checks if the role has the given permission(s). You may pass either a string or an array of permissions to check for. In the case of an array, ALL permissions must be accounted for in order for this to return true
.
$role = Role::find(1);
return $role->can('access.admin');
Retrieves an array of assigned permission slugs for the role.
$role = Role::find(1);
return $role->getPermissions();
Assigns the given permission to the role.
$role = Role::find(1);
$role->assignPermission(1);
$role->save();
Revokes the given permission from the role.
$role = Role::find(1);
$role->revokePermission(1);
$role->save();
Revokes all permissions from the role.
$role = Role::find(1);
$role->revokeAllPermissions();
$role->save();
Syncs the given permissions with the role. This will revoke any permissions not supplied.
$role = Role::find(1);
$role->syncPermissions([1, 2, 3]);
$role->save();