Package Data | |
---|---|
Maintainer Username: | Helori |
Maintainer Contact: | helori@algoart.fr (Helori Lanos) |
Package Create Date: | 2016-10-13 |
Package Last Update: | 2017-05-18 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-18 03:06:27 |
Package Statistics | |
---|---|
Total Downloads: | 69 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Define roles and permissions for Laravel users
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);
});
}
}
}
In your blade template files :
@if(Gate::forUser($user)->allows('permission-name'))
<div>this is only for allowed users</div>
@endif