UsesRoles
Functionality for user permissions ---- Addition to user class
Tags
Table of Contents
Properties
- $permissions : array<string|int, mixed>
- User Permissions
- $roles : array<string|int, mixed>
- User Roles
Methods
- assign() : bool
- Assign new role to user
- can() : bool
- Check if user has a permission
- cannot() : bool
- Check if a user does not have a permission
- is() : bool
- Check if user has a role
- isNot() : bool
- Check if user does not have a role
- permissions() : array<string|int, mixed>
- Return the user's permissions
- roles() : array<string|int, mixed>
- Return the user's roles
- unassign() : void
- Remove a role from a user
- getRolePermissions() : array<string|int, mixed>
- Get the permissions for a role
- setRolesAndPermissions() : void
- Set the roles and permissions for a user
Properties
$permissions
User Permissions
protected
array<string|int, mixed>
$permissions
= []
$roles
User Roles
protected
array<string|int, mixed>
$roles
= []
Methods
assign()
Assign new role to user
public
assign(string|array<string|int, mixed> $role) : bool
Parameters
- $role : string|array<string|int, mixed>
-
The role to assign
Return values
boolcan()
Check if user has a permission
public
can(string|array<string|int, mixed> $permission) : bool
Parameters
- $permission : string|array<string|int, mixed>
-
The permission(s) to check
Return values
boolcannot()
Check if a user does not have a permission
public
cannot(mixed $permission) : bool
Parameters
- $permission : mixed
Return values
boolis()
Check if user has a role
public
is(string|array<string|int, mixed> $role) : bool
Parameters
- $role : string|array<string|int, mixed>
-
The role(s) to check
Return values
boolisNot()
Check if user does not have a role
public
isNot(mixed $role) : bool
Parameters
- $role : mixed
Return values
boolpermissions()
Return the user's permissions
public
permissions() : array<string|int, mixed>
Return values
array<string|int, mixed>roles()
Return the user's roles
public
roles() : array<string|int, mixed>
Return values
array<string|int, mixed>unassign()
Remove a role from a user
public
unassign(string|array<string|int, mixed> $role) : void
Parameters
- $role : string|array<string|int, mixed>
-
The role(s) to revoke
getRolePermissions()
Get the permissions for a role
protected
getRolePermissions(mixed $roles) : array<string|int, mixed>
Parameters
- $roles : mixed
Return values
array<string|int, mixed>setRolesAndPermissions()
Set the roles and permissions for a user
protected
setRolesAndPermissions(string|array<string|int, mixed> $roles) : void
Parameters
- $roles : string|array<string|int, mixed>
-
The role(s) to set