class Rbac

This class is the main entry point of rbac. Usually this the interaction with this class will be done through the Entrust Facade

Properties

Application $app

Laravel application

Methods

__construct(Application $app)

Create a new confide instance.

bool
hasRole(string $guard, string|array $role, bool $requireAll = false)

Checks if the current user has a role by its name

bool
capable(string $guard, string $permission, bool $requireAll = false)

Check if the current user has a permission by its name 检测当前用户是否有权限

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

Check if the current user has a role or permission by its name

user(string $guard)

Get the currently authenticated user or null.

mixed
routeNeedsRole(string $route, array|string $roles, mixed $result = null, bool $requireAll = true)

Filters a route for a role or set of roles.

mixed
routeNeedsPermission(string $route, array|string $permissions, mixed $result = null, bool $requireAll = true)

Filters a route for a permission or set of permissions.

void
routeNeedsRoleOrPermission(string $route, array|string $roles, array|string $permissions, mixed $result = null, bool $requireAll = false)

Filters a route for role(s) and/or permission(s).

Details

at line 26
__construct(Application $app)

Create a new confide instance.

Parameters

Application $app

at line 38
bool hasRole(string $guard, string|array $role, bool $requireAll = false)

Checks if the current user has a role by its name

Parameters

string $guard 防护器
string|array $role 角色数组/字串
bool $requireAll 是否要求全部匹配

Return Value

bool

at line 55
bool capable(string $guard, string $permission, bool $requireAll = false)

Check if the current user has a permission by its name 检测当前用户是否有权限

Parameters

string $guard 防护器
string $permission

permission string

bool $requireAll 是否要求全部匹配

Return Value

bool

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

Check if the current user has a role or permission by its name

Parameters

$guard
array|string $roles

the role(s) needed

array|string $permissions

the permission(s) needed

array $options

the Options

Return Value

bool

at line 85
RbacUserContract user(string $guard)

Get the currently authenticated user or null.

Parameters

string $guard 获取用户信息

Return Value

RbacUserContract

at line 100
mixed routeNeedsRole(string $route, array|string $roles, mixed $result = null, bool $requireAll = true)

Filters a route for a role or set of roles.

If the third parameter is null then abort with status code 403. Otherwise, the $result is returned.

Parameters

string $route

Route pattern. i.e: "admin/*"

array|string $roles

The role(s) needed

mixed $result

i.e: Redirect::to('/')

bool $requireAll

User must have all roles

Return Value

mixed

at line 131
mixed routeNeedsPermission(string $route, array|string $permissions, mixed $result = null, bool $requireAll = true)

Filters a route for a permission or set of permissions.

If the third parameter is null then abort with status code 403. Otherwise the $result is returned.

Parameters

string $route

Route pattern. i.e: "admin/*"

array|string $permissions

The permission(s) needed

mixed $result

i.e: Redirect::to('/')

bool $requireAll

User must have all permissions

Return Value

mixed

at line 163
void routeNeedsRoleOrPermission(string $route, array|string $roles, array|string $permissions, mixed $result = null, bool $requireAll = false)

Filters a route for role(s) and/or permission(s).

If the third parameter is null then abort with status code 403. Otherwise, the $result is returned.

Parameters

string $route

Route pattern. i.e: "admin/*"

array|string $roles

The role(s) needed

array|string $permissions

The permission(s) needed

mixed $result

i.e: Redirect::to('/')

bool $requireAll

User must have all roles and permissions

Return Value

void