dev-master
9999999-dev http://github.com/sambenne/JukumuLaravel 5 User Roles and Permissions Extension
MIT
The Requires
- php >=5.5.0
The Development Requires
by Sam Bennett
laravel user roles permissions laravel 5
Laravel 5 User Roles and Permissions Extension
This package adds extra functionality to the built in User Authentication. This adds the ability to do User Roles and Permissions., (*1)
You should install this package with Composer. Add the following require
to your composer.json
file and run the composer install
command to install it., (*2)
{ "require": { "sbennett/jukumu": "dev-master" } }
Then in your config/app.php
add this line to the providers
array., (*3)
'SamBenne\Jukumu\Providers\JukumuServiceProvider',
To get the extra features into the User class you simply need to add inside the User class., (*4)
For example:, (*5)
use Illuminate\Database\Eloquent\Model; use SamBenne\Jukumu\Traits\JukumuRoleTrait; class User extends Model { use Authenticatable, CanResetPassword, JukumuRoleTrait; }
Once this is in you can use these new methods are automatically made available, within the class:, (*6)
setRole( $roleName )
is( $roleName )
hasRole( array $roleNames )
has( array $permissions )
There are also a helper class Jukumu
that will help with creating the roles and permissions., (*7)
Jukumu::createRole( $name, $display_name = NULL, $description = NULL, $order = 0 )
Jukumu::createPermission( $name, $group = NULL, $display_name = NULL, $description = NULL )
Jukumu::attachRole( $user, Role $role, array $permissions = [] )
Jukumu::attachPermissions( Role $role, array $permissions = [] )
This will create a role. This only requires a name however, there are extra information that you can add., (*8)
Example, (*9)
Jukumu::createRole('admin', 'Admin', 'This is my main admin role.'); Jukumu::createRole('user', 'User', 'This is the basic user role.', 1);
This will create a permission that you can attach to a role later., (*10)
The group parameter allows you to group the permissions together, this then allows for dot notation on permission checking later., (*11)
Example, (*12)
Jukumu::createPermission('view', 'blog', 'View Blog Post', 'View the blog post.'); Jukumu::createPermission('edit', 'blog', 'Edit Blog Post', 'Edit the blog post.');
There are two methods of attaching the first attachRole
allows you to attach a role to a user and the permissions to that role. The other just allows for attaching permissions to the role., (*13)
Example 1, (*14)
This attaches a role and permissions to the user., (*15)
Jukumu::attachRole(Auth::user(), Role::find(1), ['blog.view', 'blog.edit']);
Example 2, (*16)
This attaches the permissions straight to the role., (*17)
Jukumu::attachPermissions( Role::find(1), [ 'blog.view', 'blog.edit' ] );
If an error has occurred please check and add an issue with the error in the issues., (*18)
Jukumu is licensed under The MIT License (MIT)., (*19)
Laravel 5 User Roles and Permissions Extension
MIT
laravel user roles permissions laravel 5