Junges Laravel ACL is a package by Mateus Junges that helps you to associate users with permissions and permission groups.
This package stores permissions for users and groups (to which users may belong) in the database with the following core features:
- Check a user for ACL permissions
- Sync a user’s permissions
- Sync a group’s permissions
- Check permissions in the view layer with
@can
or provided custom directives
At the heart of this package is the UserTrait
:
use Illuminate\Foundation\Auth\User as Authenticatable;
use Junges\ACL\Traits\UsersTrait;
class User extends Authenticatable
{
use UserTrait;
//
}
You can sync user and group permissions with the syncPermissions()
method:
// With permission id array:
$user->syncPermissions([1, 2, 4]);
// With permission slugs array:
$user->syncPermissions(['permission-slug-1', 'permission-slug-2']);
// With instance of permission model arrays:
$user->syncPermissions([Permission::find(1), Permission::find(2)]);
// Just as above you can sync group permissions. Here's the id version:
$group->syncPermissions([1, 2, 4]);
Check out the usage documentation for a complete list of methods and package capabilities. You can learn more about this package and check out the source code on GitHub at mateusjunges/laravel-acl.
0 comments:
Post a Comment
Thanks