helori / laravel-permission
Define roles and permissions for Laravel users
dev-master
2017-05-18 07:19 UTC
Requires
- php: >=5.5.9
This package is auto-updated.
Last update: 2024-12-09 01:56:35 UTC
README
Define roles and permissions for Laravel users
Installation and setup
composer require helori/laravel-permission:dev-master
Configure your application:
// config/app.php 'providers' => [ ... Helori\LaravelPermission\PermissionServiceProvider::class, ];
Publish and run the migrations:
php artisan vendor:publish --provider="Helori\LaravelPermission\PermissionServiceProvider" --tag="migrations" php artisan migrate
In your app/Providers/AuthServiceProvider.php :
use Helori\LaravelPermission\Models\Permission; ... class AuthServiceProvider extends ServiceProvider { ... public function boot() { ... $permissions = Permission::all(); foreach($permissions as $permission){ Gate::define($permission->name, function (User $user) use($permission) { return $user->hasPermission($permission); }); } } }
Usage example
In your blade template files :
@if(Gate::forUser($user)->allows('permission-name')) <div>this is only for allowed users</div> @endif