Skip to content

Commit 6fb996f

Browse files
authored
Merge pull request #311 from datamweb/docs-add-getPermissions-getGroups-hasPermission
docs: add explanation of methods `getGroups()`,`getPermissions()` ,`hasPermission()`
2 parents 9c1822c + 4da51b3 commit 6fb996f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/authorization.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
- [Authorizing Users](#authorizing-users)
99
- [can()](#can)
1010
- [inGroup()](#ingroup)
11+
- [hasPermission()](#haspermission)
1112
- [Managing User Permissions](#managing-user-permissions)
1213
- [addPermission()](#addpermission)
1314
- [removePermission()](#removepermission)
1415
- [syncPermissions()](#syncpermissions)
16+
- [getPermissions()](#getpermissions)
1517
- [Managing User Groups](#managing-user-groups)
1618
- [addGroup()](#addgroup)
1719
- [removeGroup()](#removegroup)
1820
- [syncGroups()](#syncgroups)
21+
- [getGroups()](#getgroups)
1922

2023
Authorization happens once a user has been identified through authentication. It is the process of
2124
determining what actions a user is allowed to do within your site.
@@ -115,6 +118,16 @@ if (! $user->inGroup('superadmin', 'admin')) {
115118
}
116119
```
117120

121+
#### hasPermission()
122+
123+
Checks to see if the user has the permission set directly on themselves. This disregards any groups they are part of.
124+
125+
```php
126+
if (! $user->hasPermission('users.create')) {
127+
//
128+
}
129+
```
130+
118131
## Managing User Permissions
119132

120133
Permissions can be granted on a user level as well as on a group level. Any user-level permissions granted will
@@ -147,6 +160,14 @@ not in this list will be removed.
147160
$user->syncPermissions('admin.access', 'beta.access');
148161
```
149162

163+
#### getPermissions()
164+
165+
Returns all permissions this user has assigned directly to them.
166+
167+
```php
168+
$user->getPermissions();
169+
```
170+
150171
## Managing User Groups
151172

152173
#### addGroup()
@@ -175,3 +196,11 @@ not in this list will be removed.
175196
```php
176197
$user->syncGroups('admin', 'beta');
177198
```
199+
200+
#### getGroups()
201+
202+
Returns all groups this user is a part of.
203+
204+
```php
205+
$user->getGroups();
206+
```

0 commit comments

Comments
 (0)