Skip to content

Document 'doesntHavePermission' and 'isNotAbleTo' methods #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/docs/8.x/usage/roles-and-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ $user->hasPermission('edit-user'); // false
$user->isAbleTo('edit-user'); // false
$user->hasPermission('create-post'); // true
$user->isAbleTo('create-post'); // true
$user->doesntHavePermission('create-post'); // false
$user->isNotAbleTo('create-post'); // false
```

::: tip NOTE
Expand Down Expand Up @@ -168,20 +170,24 @@ $user->hasRole(['owner', 'admin']); // true
$user->hasRole(['owner', 'admin'], true); // false, user does not have admin role
$user->hasPermission(['edit-user', 'create-post']); // true
$user->hasPermission(['edit-user', 'create-post'], true); // false, user does not have edit-user permission
$user->doesntHavePermission(['edit-user', 'create-post']); // true
$user->doesntHavePermission(['edit-user', 'create-post'], true); // false, user does have create-post permission
```

You can have as many `Role`s as you want for each `User` and vice versa. Also, you can have as many direct `Permissions`s as you want for each `User` and vice versa.

The `Laratrust` class has shortcuts to both `hasPermission()` and `hasRole()` for the currently logged in user:
The `Laratrust` class has shortcuts to `hasPermission()` and `doesntHavePermission()` and `hasRole()` for the currently logged in user:

```php
Laratrust::hasRole('role-name');
Laratrust::hasPermission('permission-name');
Laratrust::doesntHavePermission('permission-name');

// is identical to

Auth::user()->hasRole('role-name');
Auth::user()->hasPermission('permission-name');
Auth::user()->doesntHavePermission('permission-name');
```

You can also use wildcard to check any matching permission by doing:
Expand Down