islamrumon/laravel-acl
Laravel ACL provides database-backed roles, groups, and permissions for Laravel 5.8+. Note: unmaintained since Jan 2024; consider spatie/laravel-permission instead.
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');
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);
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']);
How can I help you explore Laravel packages today?