dev-master
9999999-dev https://github.com/tadeas-j/permissionsAn easy permissions for Laravel 5.
laravel permissions
An easy permissions for Laravel 5.
An easy Laravel 5 permissions package., (*1)
require : { "tadeas-j/permissions": "dev-master" }
Next, what you need to do is to run., (*2)
composer update
Now, you have successfully installed the package., (*3)
Next required step is to add package's service provider to laravel application config, which is located in 'app/config/app.php'., (*4)
'Permissions' => 'Permissions\Providers\PermissionsProvider'
And lastly for configuring our permissions and roles we need to publish 'config.php' file to '/config/permissions/config.php'., (*5)
php artisan vendor:publish
I highly recommend u to use package's prepared facade, only thing, what you need to do, is to register it in 'app/config/app.php'., (*6)
'Permissions' => 'Permissions\Facades\Permissions'
Configuration file should be published to '/config/permissions/config.php'. If you missed it, you can do it easilly with calling this command., (*7)
php artisan vendor:publish
At first, you need to put 'role' column to your users table. Default 'config.php' file looks like this., (*8)
$aliases = array( 'manage' => ['create', 'delete', 'edit'] ); $roles = array( 'admin' => [ 'manage.users', ] );
This means, that role 'admin' is allowed to manage.users, 'manage' is alias to 'create', 'delete' and 'edit'. So it is the same like this., (*9)
$aliases = array(); $roles = array( 'admin' => [ 'create.users', 'delete.users', 'edit.users', ] );
So let's think about, that we have got one user with role 'admin', 'admin' role is allowed for 'create.users', and the code below is exactly, what we need to do in our creating proccess., (*10)
Permissions::can('create.users');
This will get our logged user, his permissions and then it will check them. If we want to check permissions of user with ID 1 for example, we will just easilly do this., (*11)
Permissions::can('create.users', User::find(1));
There is also a trait, what you can use., (*12)
Permissions\PermissionsTrait
After using this trait in your user model, you will be allowed to do something like this., (*13)
Auth::user()->can('create.users');
An easy permissions for Laravel 5.
laravel permissions