interface RbacUserContract

用户约束

Methods

BelongsToMany
roles()

Many-to-Many relations with Role.

bool
hasRole(string|array $name, bool $require_all = false)

Checks if the user has a role by its name.

bool
capable(string|array $permission, bool $require_all = false)

Check if user has a permission by its name.

array|bool
ability(string|array $roles, string|array $permissions, array $options = [])

Checks role(s) and permission(s).

attachRole(int|int[]|object|object[] $id)

Alias to eloquent many-to-many relation's attach() method.

detachRole(int|int[]|object|object[] $id)

Alias to eloquent many-to-many relation's detach() method.

Details

at line 19
BelongsToMany roles()

Many-to-Many relations with Role.

Return Value

BelongsToMany

at line 27
bool hasRole(string|array $name, bool $require_all = false)

Checks if the user has a role by its name.

Parameters

string|array $name

role name or array of role names

bool $require_all

all roles in the array are required

Return Value

bool

at line 35
bool capable(string|array $permission, bool $require_all = false)

Check if user has a permission by its name.

Parameters

string|array $permission

permission string or array of permissions

bool $require_all

all permissions in the array are required

Return Value

bool

at line 45
array|bool ability(string|array $roles, string|array $permissions, array $options = [])

Checks role(s) and permission(s).

Parameters

string|array $roles

Array of roles or comma separated string

string|array $permissions

array of permissions or comma separated string

array $options

validate_all (true|false) or return_type (boolean|array|both)

Return Value

array|bool

Exceptions

InvalidArgumentException

at line 51
attachRole(int|int[]|object|object[] $id)

Alias to eloquent many-to-many relation's attach() method.

Parameters

int|int[]|object|object[] $id

角色ID, 角色, 角色数组, ID 数组

at line 57
detachRole(int|int[]|object|object[] $id)

Alias to eloquent many-to-many relation's detach() method.

Parameters

int|int[]|object|object[] $id

角色ID, 角色, 角色数组, ID 数组