2017 © Pedro Peláez
 

library privileges

Small Role-Permission integration for laravel

image

matthc/privileges

Small Role-Permission integration for laravel

  • Saturday, May 14, 2016
  • by matthc
  • Repository
  • 1 Watchers
  • 2 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Privileges

SensioLabsInsight, (*1)

This is a small role-permission integration for laravel projects. I know Entrust exists but i wanted to try it myself., (*2)

Installation

Download the package into the vendor folder, (*3)

composer require matthc/privileges

Add the Service Provider to config/app.php, (*4)

...
MatthC\Privileges\PrivilegeServiceProvider::class,
...

publish files, (*5)

$ php artisan vendor:publish

Run the migrations, (*6)

$ php artisan migrate

Adjust the settings in config/privileges.php and run the following commands to add the roles and permissions you want., (*7)

$ php artisan privileges:db:seed

If you want to add users with specific roles, run the following command:, (*8)

$ php artisan privileges:db:users

Add the trait to the usermodel, (*9)

use MatthC\Privileges\Traits\PrivilegeUserTrait;

class User extends Authenticatable
{
    use PrivilegeUserTrait;

    ...
}

Usage

User has role

To check if a user has a specific role:, (*10)

//one role
$user->hasRole('admin'); //returns true/false

//multiple roles
$user->hasRole(['admin', 'author']); //returns true if the user has one of these roles

//user must have all roles
$user->hasRole(['admin', 'author'], true);

User has permission

To check if a user has a specific permission:, (*11)

//one permission
$user->can('create_post');

//multiple permissions
$user->can(['create_post', 'update_post']);

//all true
$user->can(['create_post', 'update_post'], true);

Middleware

You can also use predefined middleware. Add the following lines to the route middleware array in app/Http/kernel.php, (*12)

protected $routeMiddleware = [
        ...
        'role' => \MatthC\Privileges\Middleware\PrivilegeRoleMiddleware::class,
        'permission' => \MatthC\Privileges\Middleware\PrivilegePermissionMiddleware::class,
    ];

Example usage:, (*13)

Route::group(['middleware' => ['role:admin']], function() {
    //add routes
});

The Versions

14/05 2016

dev-master

9999999-dev https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Matthieu MatthC

laravel roles permissions

14/05 2016

0.2.0

0.2.0.0 https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Matthieu MatthC

laravel roles permissions

14/05 2016

dev-develop

dev-develop https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Matthieu MatthC

laravel roles permissions

02/02 2016

0.1.3

0.1.3.0 https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Matthieu MatthC

laravel roles permissions

25/01 2016

0.1.2

0.1.2.0 https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Matthieu MatthC

laravel roles permissions

18/01 2016

0.1.1

0.1.1.0 https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Matthieu MatthC

laravel roles permissions

10/01 2016

0.1

0.1.0.0 https://github.com/MatthC

Small Role-Permission integration for laravel

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Matthieu MatthC

laravel roles permissions