PHP Trait Spatie\Permission\Traits\HasRoles

Inheritance: use trait HasPermissions, use trait Spatie\Permission\Traits\RefreshesPermissionCache
ファイルを表示 Open project: spatie/laravel-permission

Public Methods

Method Description
assignRole ( $roles ) : Spatie\Permission\Contracts\Role Assign the given role to the user.
hasAllRoles ( string | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean Determine if the user has all of the given role(s).
hasAnyRole ( string | array | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean Determine if the user has any of the given role(s).
hasPermission ( Spatie\Permission\Contracts\Permission $permission ) : boolean
hasPermissionTo ( string | Spatie\Permission\Contracts\Permission $permission ) : boolean Determine if the user may perform the given permission.
hasRole ( string | array | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean Determine if the user has (one of) the given role(s).
permissions ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany A user may have multiple direct permissions.
removeRole ( string | Spatie\Permission\Contracts\Role $role ) Revoke the given role from the user.
roles ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany A user may have multiple roles.
syncRoles ( $roles ) Remove all current roles and set the given ones.

Protected Methods

Method Description
getStoredRole ( $role ) : Spatie\Permission\Contracts\Role
hasDirectPermission ( string | Spatie\Permission\Contracts\Permission $permission ) : boolean Determine if the user has the given permission.
hasPermissionViaRole ( Spatie\Permission\Contracts\Permission $permission ) : boolean Determine if the user has, via roles, the given permission.

Method Details

assignRole() public method

Assign the given role to the user.
public assignRole ( $roles ) : Spatie\Permission\Contracts\Role
$roles
return Spatie\Permission\Contracts\Role

getStoredRole() protected method

protected getStoredRole ( $role ) : Spatie\Permission\Contracts\Role
$role
return Spatie\Permission\Contracts\Role

hasAllRoles() public method

Determine if the user has all of the given role(s).
public hasAllRoles ( string | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean
$roles string | Spatie\Permission\Contracts\Role | Illuminate\Support\Collection
return boolean

hasAnyRole() public method

Determine if the user has any of the given role(s).
public hasAnyRole ( string | array | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean
$roles string | array | Spatie\Permission\Contracts\Role | Illuminate\Support\Collection
return boolean

hasDirectPermission() protected method

Determine if the user has the given permission.
protected hasDirectPermission ( string | Spatie\Permission\Contracts\Permission $permission ) : boolean
$permission string | Spatie\Permission\Contracts\Permission
return boolean

hasPermission() public method

Deprecation: deprecated since version 1.0.1, use hasPermissionTo instead Determine if the user may perform the given permission.
public hasPermission ( Spatie\Permission\Contracts\Permission $permission ) : boolean
$permission Spatie\Permission\Contracts\Permission
return boolean

hasPermissionTo() public method

Determine if the user may perform the given permission.
public hasPermissionTo ( string | Spatie\Permission\Contracts\Permission $permission ) : boolean
$permission string | Spatie\Permission\Contracts\Permission
return boolean

hasPermissionViaRole() protected method

Determine if the user has, via roles, the given permission.
protected hasPermissionViaRole ( Spatie\Permission\Contracts\Permission $permission ) : boolean
$permission Spatie\Permission\Contracts\Permission
return boolean

hasRole() public method

Determine if the user has (one of) the given role(s).
public hasRole ( string | array | Spatie\Permission\Contracts\Role | Collection $roles ) : boolean
$roles string | array | Spatie\Permission\Contracts\Role | Illuminate\Support\Collection
return boolean

permissions() public method

A user may have multiple direct permissions.
public permissions ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

removeRole() public method

Revoke the given role from the user.
public removeRole ( string | Spatie\Permission\Contracts\Role $role )
$role string | Spatie\Permission\Contracts\Role

roles() public method

A user may have multiple roles.
public roles ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

syncRoles() public method

Remove all current roles and set the given ones.
public syncRoles ( $roles )
$roles