PHP Trait Laratrust\Traits\LaratrustUserTrait

Show file Open project: santigarcor/laratrust

Public Methods

Method Description
ability ( string | array $roles, string | array $permissions, $group = null, array $options = [] ) : array | boolean Checks role(s) and permission(s).
attachPermission ( mixed $permission ) : Illuminate\Database\Eloquent\Model Alias to eloquent many-to-many relation's attach() method.
attachPermissions ( mixed $permissions ) : Illuminate\Database\Eloquent\Model Attach multiple permissions to a user
attachRole ( mixed $role, $group = null ) : Illuminate\Database\Eloquent\Model Alias to eloquent many-to-many relation's attach() method.
attachRoles ( mixed $roles, $group = null ) : Illuminate\Database\Eloquent\Model Attach multiple roles to a user
bootLaratrustUserTrait ( ) : void | boolean Boot the user model Attach event listener to remove the many-to-many records when trying to delete Will NOT delete any records if the user model uses soft deletes.
cachedPermissions ( ) : Illuminate\Database\Eloquent\Collection Tries to return all the cached permissions of the user and if it can't bring the permissions from the cache, it would bring them back from the DB
cachedRoles ( ) : Illuminate\Database\Eloquent\Collection Tries to return all the cached roles of the user and if it can't bring the roles from the cache, it would bring them back from the DB
can ( string | array $permission, string | boolean $group = null, boolean $requireAll = false ) : boolean Check if user has a permission by its name.
detachPermission ( mixed $permission ) : Illuminate\Database\Eloquent\Model Alias to eloquent many-to-many relation's detach() method.
detachPermissions ( mixed $permissions = null ) : Illuminate\Database\Eloquent\Model Detach multiple permissions from a user
detachRole ( mixed $role, $group = null ) : Illuminate\Database\Eloquent\Model Alias to eloquent many-to-many relation's detach() method.
detachRoles ( mixed $roles = null, $group = null ) : Illuminate\Database\Eloquent\Model Detach multiple roles from a user
flushCache ( ) : void Flush the user's cache
groups ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany Many-to-Many relations with Group.
hasRole ( string | array $name, string | boolean $group = null, boolean $requireAll = false ) : boolean Checks if the user has a role by its name.
owns ( Model $thing ) : boolean Checks if the user owns the thing
permissions ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany Many-to-Many relations with Permission.
roles ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany Many-to-Many relations with Role.
scopeWherePermissionIs ( Illuminate\Database\Eloquent\Builder $query, string $permission = '' ) : Illuminate\Database\Eloquent\Builder This scope allows to retrive users with an specific permission
scopeWhereRoleIs ( Illuminate\Database\Eloquent\Builder $query, string $role = '' ) : Illuminate\Database\Eloquent\Builder This scope allows to retrive users with an specific role

Method Details

ability() public method

Checks role(s) and permission(s).
public ability ( string | array $roles, string | array $permissions, $group = null, array $options = [] ) : array | boolean
$roles string | array Array of roles or comma separated string
$permissions string | array Array of permissions or comma separated string.
$options array validate_all (true|false) or return_type (boolean|array|both)
return array | boolean

attachPermission() public method

Alias to eloquent many-to-many relation's attach() method.
public attachPermission ( mixed $permission ) : Illuminate\Database\Eloquent\Model
$permission mixed
return Illuminate\Database\Eloquent\Model

attachPermissions() public method

Attach multiple permissions to a user
public attachPermissions ( mixed $permissions ) : Illuminate\Database\Eloquent\Model
$permissions mixed
return Illuminate\Database\Eloquent\Model

attachRole() public method

Alias to eloquent many-to-many relation's attach() method.
public attachRole ( mixed $role, $group = null ) : Illuminate\Database\Eloquent\Model
$role mixed
return Illuminate\Database\Eloquent\Model

attachRoles() public method

Attach multiple roles to a user
public attachRoles ( mixed $roles, $group = null ) : Illuminate\Database\Eloquent\Model
$roles mixed
return Illuminate\Database\Eloquent\Model

bootLaratrustUserTrait() public static method

Boot the user model Attach event listener to remove the many-to-many records when trying to delete Will NOT delete any records if the user model uses soft deletes.
public static bootLaratrustUserTrait ( ) : void | boolean
return void | boolean

cachedPermissions() public method

Tries to return all the cached permissions of the user and if it can't bring the permissions from the cache, it would bring them back from the DB
public cachedPermissions ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

cachedRoles() public method

Tries to return all the cached roles of the user and if it can't bring the roles from the cache, it would bring them back from the DB
public cachedRoles ( ) : Illuminate\Database\Eloquent\Collection
return Illuminate\Database\Eloquent\Collection

can() public method

Check if user has a permission by its name.
public can ( string | array $permission, string | boolean $group = null, boolean $requireAll = false ) : boolean
$permission string | array Permission string or array of permissions.
$group string | boolean Group name or requiredAll roles.
$requireAll boolean All permissions in the array are required.
return boolean

detachPermission() public method

Alias to eloquent many-to-many relation's detach() method.
public detachPermission ( mixed $permission ) : Illuminate\Database\Eloquent\Model
$permission mixed
return Illuminate\Database\Eloquent\Model

detachPermissions() public method

Detach multiple permissions from a user
public detachPermissions ( mixed $permissions = null ) : Illuminate\Database\Eloquent\Model
$permissions mixed
return Illuminate\Database\Eloquent\Model

detachRole() public method

Alias to eloquent many-to-many relation's detach() method.
public detachRole ( mixed $role, $group = null ) : Illuminate\Database\Eloquent\Model
$role mixed
return Illuminate\Database\Eloquent\Model

detachRoles() public method

Detach multiple roles from a user
public detachRoles ( mixed $roles = null, $group = null ) : Illuminate\Database\Eloquent\Model
$roles mixed
return Illuminate\Database\Eloquent\Model

flushCache() public method

Flush the user's cache
public flushCache ( ) : void
return void

groups() public method

Many-to-Many relations with Group.
public groups ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

hasRole() public method

Checks if the user has a role by its name.
public hasRole ( string | array $name, string | boolean $group = null, boolean $requireAll = false ) : boolean
$name string | array Role name or array of role names.
$group string | boolean Group name or requiredAll roles.
$requireAll boolean All roles in the array are required.
return boolean

owns() public method

Checks if the user owns the thing
public owns ( Model $thing ) : boolean
$thing Model
return boolean

permissions() public method

Many-to-Many relations with Permission.
public permissions ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

roles() public method

Many-to-Many relations with Role.
public roles ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany
return Illuminate\Database\Eloquent\Relations\BelongsToMany

scopeWherePermissionIs() public method

This scope allows to retrive users with an specific permission
public scopeWherePermissionIs ( Illuminate\Database\Eloquent\Builder $query, string $permission = '' ) : Illuminate\Database\Eloquent\Builder
$query Illuminate\Database\Eloquent\Builder
$permission string
return Illuminate\Database\Eloquent\Builder

scopeWhereRoleIs() public method

This scope allows to retrive users with an specific role
public scopeWhereRoleIs ( Illuminate\Database\Eloquent\Builder $query, string $role = '' ) : Illuminate\Database\Eloquent\Builder
$query Illuminate\Database\Eloquent\Builder
$role string
return Illuminate\Database\Eloquent\Builder