You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/quickstart.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,9 @@ NOTE: The examples assume that you have run the setup script and that you have c
20
20
-[Assign Permissions to a Group](#assign-permissions-to-a-group)
21
21
-[Assign Permissions to a User](#assign-permissions-to-a-user)
22
22
-[Check If a User Has Permission](#check-if-a-user-has-permission)
23
+
-[Adding A Group To A User](#adding-a-group-to-a-user)
24
+
-[Removing A Group From A User](#removing-a-group-from-a-user)
25
+
-[Checking If User Belongs To A Group](#checking-if-user-belongs-to-a-group)
23
26
-[Managing Users](#managing-users)
24
27
-[Creating Users](#creating-users)
25
28
-[Deleting Users](#deleting-users)
@@ -208,7 +211,50 @@ if (! auth()->user()->can('users.create')) {
208
211
209
212
Note: The example above can also be done through a [controller filter](https://codeigniter.com/user_guide/incoming/filters.html) if you want to apply it to multiple pages of your site.
210
213
214
+
### Adding A Group To A User
211
215
216
+
Groups are assigned to a user via the `addGroup` method. You can pass multiple groups in and they will all be assigned to the user.
217
+
218
+
```php
219
+
$user = auth()->user();
220
+
$user->addGroup('admin', 'beta');
221
+
```
222
+
223
+
This will add all new groups. You can also sync groups so that the user ONLY belongs to the groups directly assigned to them. Any not in the provided list are removed from the user.
224
+
225
+
```php
226
+
$user = auth()->user();
227
+
$user->syncGroups('admin', 'beta');
228
+
```
229
+
230
+
### Removing A Group From A User
231
+
232
+
Groups are removed from a user via the `removeGroup` method. Multiple groups may be removed at once by passing all of their names into the method.
233
+
234
+
```php
235
+
$user = auth()->user();
236
+
$user->removeGroup('admin', 'beta');
237
+
```
238
+
239
+
### Checking If User Belongs To A Group
240
+
241
+
You can check if a user belongs to a group with the `inGroup` method.
242
+
243
+
```php
244
+
$user = auth()->user();
245
+
if($user->inGroup('admin')) {
246
+
// do something
247
+
}
248
+
```
249
+
250
+
You can pass more than one group to the method and it will return `true` if the user belongs to any of the specified groups.
0 commit comments