juhniorsantos/laravel-simple-acl is a Laravel package for laravel simple acl.
It currently has 0 GitHub stars and 253 downloads on Packagist (latest version 0.3.0).
Install it with composer require juhniorsantos/laravel-simple-acl.
Discover more Laravel packages by juhniorsantos
or browse all Laravel packages to compare alternatives.
Last updated
{
"require": {
"rodrigopedra/laravel-simple-acl": "^1.0"
}
}
App\Models\User\RodrigoPedra\LaravelSimpleACL\Concerns\HasACL trait to the project's User modelCreate roles and permissions through the included RodrigoPedra\LaravelSimpleACL\Models\Role and
RodrigoPedra\LaravelSimpleACL\Models\Permission Eloquent models.
Permissions are meant to be grouped into a role, you can create a database seeder, or migration for your initial setup, for example:
$addUsers = Permission::create([
'label' => 'add-users',
'description' => 'User is allowed to create new users',
'sort_index' => 1,
]);
$removeUsers = Permission::create([
'label' => 'remove-users',
'description' => 'User is allowed to remove users',
'sort_index' => 2,
]);
Role::create([
'label' => 'admin',
'sort_index' => 1,
])->attachPermission($addUsers)->attachPermission($removeUsers);
Role::create([
'label' => 'leader',
'sort_index' => 2,
])->attachPermission($addUsers);
You can then add or remove roles to individual users using the included trait's helper methods:
$user->attachRole(Role::hasLabel('admin')->first());
$user->detachRole(Role::hasLabel('leader')->first());
If you add the \RodrigoPedra\LaravelSimpleACL\Http\Middleware\LoadSimpleACL middleware
to your middleware stack, you can use Laravel's gate to check for permissions:
if ($user->can('add-users')) {
// do something
}
Even on blade views
@can('add-users')
{{-- do something --}}
@endcan