Skip to content

User Permissions

User Permissions is an extended version of HasRole that allows us to directly add custom permissions to a User. To implement this setup, you need to extend Yajra\Acl\Traits\HasRoleAndPermission trait on your User model.

class User extends Authenticatable
use HasRoleAndPermission;


Retrieves an array of assigned permission slugs for the user.

$user = User::find(1);
return $user->getPermissions();

grantPermission($ids, array $attributes = [], $touch = true)

Grant the given permission to the user.

$user = User::find(1);
$permissions = Permission::all();


Grant the given permission slug to the user.

$user = User::find(1);
$permissions = ['create-post', 'view-post'];


Grant the given permission resource to the user.

$user = User::find(1);
$resources = ['Users', 'Posts'];

revokePermission($ids = null, $touch = true)

Revokes the given permission from the user.

$user = User::find(1);
$user->revokePermission([1, 2]);


Revokes the given permission by slug from the user.

$user = User::find(1);
$user->revokePermissionBySlug(['create-posts', 'update-posts']);

##revokeAllPermissions() Revokes all permissions from the user.

$user = User::find(1);

syncPermissions($ids, $detaching = true)

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

$user = User::find(1);
$user->syncPermissions([1, 2, 3]);