daltcore / permissions
Laravel permissions handler
Installs: 2 466
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.6.0
- illuminate/support: 5.*|6.*|7.*|8.*
README
Laravel permissions handler, on your own model
Install
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;
Usage
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');
Middleware
Route::group(['middleware' => 'permission:create-users'], function () { ... Route::group(['middleware' => 'role:admin'], function () {
Blade directives
@hasrole('admin')
I'm admin
@else
I'm not admin
@endhasrole
@haspermission('create-users')
I can create users
@else
I cannot create users
@endhaspermission
License
The MIT License (MIT). Please see License File for more information.