Skip to content

Shinobi Trait

Carlos G. Camacho O edited this page May 15, 2018 · 1 revision

The following methods will become available from your User model.

isRole($roleSlug)

Checks if the user is under the given role.

Auth::user()->isRole('administrator');

You may also use magic methods:

Auth::user()->isAdministrator();

can($permission)

Checks if the user has the given permission(s). You may pass either a string or an array of permissions to check for. In the case of an array, ALL permissions must be accountable for in order for this to return true.

Auth::user()->can('access.admin');

or

Auth::user()->can(['access.admin', 'view.users']);

assignRole($roleId)

Assign the given role to the user.

Auth::user()->assignRole(1);

revokeRole($roleId)

Revokes the given role from the user.

Auth::user()->revokeRole(1);

revokeAllRoles()

Revokes all roles from the user.

Auth::user()->revokeAllRoles();

syncRoles([$roleIds])

Syncs the given roles with the user. This will revoke any roles not supplied.

Auth::user()->syncRoles([1, 2, 3]);