Laravel permissions handler, on your own model
Via Composer
$ composer require daltcore/laravel-permissions
In your config/app.php at the Package Service Providers
DALTCORE\Permissions\ServiceProvider::class,
In your config/app.php at the Class Aliases
'Permission' => DALTCORE\Permissions\Facade::class,
In your app/Http/Kernel.php in $routeMiddleware
'permission' => \DALTCORE\Permissions\Http\Middleware\CheckPermission::class,
'role' => \DALTCORE\Permissions\Http\Middleware\CheckRole::class,
Publish migrations
php artisan vendor:publish --tag=dpm-migrations
Run migrations
php artisan migrate
Add trait to User model
use DALTCORE\Permissions\Traits\Permissible;
Add a role
Permission::addRole('admin');
Add a permission
Permission::addPermission('create-users', 'a small description');
Link permission to role
Permission::addPermissionToRole('admin', 'create-users');
Link role to user
User::find(1)->giveRole('admin');
Check if user has role
User::find(1)->hasRole('admin');
Check if user has permission
User::find(1)->hasPermission('create-users');
Drop role from user
User::find(1)->dropRole('admin');
Drop permission from role
Permission::dropPermissionFromRole('admin', 'create-users');
Remove a permission
Permission::removePermission('admin');
Remove a role
Permission::removeRole('admin');
Route::group(['middleware' => 'permission:create-users'], function () {
...
Route::group(['middleware' => 'role:admin'], function () {
@hasrole('admin')
I'm admin
@else
I'm not admin
@endhasrole
@haspermission('create-users')
I can create users
@else
I cannot create users
@endhaspermission
The MIT License (MIT). Please see License File for more information.