Group permissions
#Assigning permissions to groups:
You can add permissions to groups using the assignPermission
method:
$group->assignPermission('create posts');
To remove group permissions, use the revokePermission
method:
$group->revokePermission('create posts');
#Assigning groups to users
To assign a user to a given group, you can use two methods:
$group->assignUser($user);
// Or:
$user->assignGroup($group);
To remove a group from a user, use the revokeGroup
method:
$user->revokeGroup(Group::find(1));
$user->revokeGroup('test group');
$user->revokeGroup(1);
#Check if user has groups
You can check if user has a given group, use the hasGroup
method:
$user->hasGroup('test-group');
$user->hasGroup(Group::find(1));
$user->hasGroup(1);
Like permissions, you can check if users has any of a given array of groups:
$user->hasAnyGroup(['group one', 'group two']);
Or, if users has all groups:
$user->hasAllGroups(['group one', 'group two']);