Skip to content
Icon

WARNING You're browsing the documentation for an old version of LARAVEL-ACL. Consider upgrading your project to laravel-acl 10.0.

Authorization

The following methods will become available from your User model once you use HasRole trait.

isRole($roleSlug)

Checks if the user is under the given role.

auth()->user()->isRole('administrator');

You may also use magic methods:

auth()->user()->isAdministrator();

hasRole($roleSlug)

Check if user has the given role. A user must have at least one role order for this to return true.

auth()->user()->hasRole('administrator');

Or pass an array of roles.

auth()->user()->hasRole(['administrator', 'registered']);

can($permission)

Checks if the user has the given permission.

auth()->user()->can('users.create');

canAtLeast([$permissions])

Checks if the user has the given permission(s). At least one permission must be accountable for in order for this to return true.

auth()->user()->canAtLeast(['users.create', 'users.view']);

canAccess([$permissionOrRole])

Checks if the user has the given permission(s) or role(s). At least one permission or role must be accountable for in order for this to return true.

auth()->user()->canAccess(['users.create', 'users.view', 'administrator']);