PHP Trait Laratrust\Traits\LaratrustUserTrait

Afficher le fichier Open project: santigarcor/laratrust

Méthodes publiques

Méthode 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 méthode

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)
Résultat array | boolean

attachPermission() public méthode

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

attachPermissions() public méthode

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

attachRole() public méthode

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

attachRoles() public méthode

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

bootLaratrustUserTrait() public static méthode

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
Résultat void | boolean

cachedPermissions() public méthode

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
Résultat Illuminate\Database\Eloquent\Collection

cachedRoles() public méthode

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
Résultat Illuminate\Database\Eloquent\Collection

can() public méthode

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.
Résultat boolean

detachPermission() public méthode

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

detachPermissions() public méthode

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

detachRole() public méthode

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

detachRoles() public méthode

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

flushCache() public méthode

Flush the user's cache
public flushCache ( ) : void
Résultat void

groups() public méthode

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

hasRole() public méthode

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.
Résultat boolean

owns() public méthode

Checks if the user owns the thing
public owns ( Model $thing ) : boolean
$thing Model
Résultat boolean

permissions() public méthode

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

roles() public méthode

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

scopeWherePermissionIs() public méthode

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
Résultat Illuminate\Database\Eloquent\Builder

scopeWhereRoleIs() public méthode

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
Résultat Illuminate\Database\Eloquent\Builder