PHP Trait App\Traits\UserHasPermissionsTrait

Show file Open project: sroutier/laravel-5.1-enterprise-starter-kit

Public Methods

Method Description
attachPermission ( $permission ) Alias to eloquent many-to-many relation's attach() method.
attachPermissions ( mixed $permissions ) Attach multiple permissions to a user
boot ( ) : 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.
can ( $permission, boolean $requireAll = false ) : boolean Overwrites EntrustUserTrait::can(.
canInRoles ( $permission, boolean $requireAll = false ) : boolean Code copy of EntrustUserTrait::can(.
detachPermission ( mixed $permission ) Alias to eloquent many-to-many relation's detach() method.
detachPermissions ( mixed $permissions ) Detach multiple permissions from a user
hasPermission ( string | array $name, boolean $requireAll = false ) : boolean Checks if the user has a permission by its name.
permissions ( ) : Illuminate\Database\Eloquent\Relations\BelongsToMany Many-to-Many relations with Permission.

Method Details

attachPermission() public method

Alias to eloquent many-to-many relation's attach() method.
public attachPermission ( $permission )

attachPermissions() public method

Attach multiple permissions to a user
public attachPermissions ( mixed $permissions )
$permissions mixed

boot() 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 boot ( ) : void | boolean
return void | boolean

can() public method

..), first checks if the permission(s) are directly associated to the user model, using ->hasPermission(), then may if required check if permission(s) are associated through the roles, using ->canInRole().
public can ( $permission, boolean $requireAll = false ) : boolean
$permission
$requireAll boolean
return boolean

canInRoles() public method

..) with the one addition to check if a role is enabled first the check if a permission is also enabled before returning true.
public canInRoles ( $permission, boolean $requireAll = false ) : boolean
$permission
$requireAll boolean
return boolean

detachPermission() public method

Alias to eloquent many-to-many relation's detach() method.
public detachPermission ( mixed $permission )
$permission mixed

detachPermissions() public method

Detach multiple permissions from a user
public detachPermissions ( mixed $permissions )
$permissions mixed

hasPermission() public method

Checks if the user has a permission by its name.
public hasPermission ( string | array $name, boolean $requireAll = false ) : boolean
$name string | array Permission name or array of permission names.
$requireAll boolean All roles in the array are required.
return boolean

permissions() public method

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