2017 © Pedro Peláez
 

library permissions

Laravel 5 package for handling user roles and permissions.

image

s00d/permissions

Laravel 5 package for handling user roles and permissions.

  • Friday, December 4, 2015
  • by s00d
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Permissions

Tiny Laravel 5 package for handling user roles and permissions., (*1)

Installation

Add the following to the require key of your composer.json file:, (*2)

"s00d/permissions": "dev-master"

Run $ composer update., (*3)

Navigate to your config/app.php file and add 's00d\Permissions\PermissionsServiceProvider' to the $providers array., (*4)

Create the tables by running $ php artisan migrate package="s00d/permissions". Ensure that your users table exists first., (*5)

Navigate to your models/User.php file and add the s00d\Permissions\Can trait below the class decloration line:, (*6)

class User extends Eloquent implements UserInterface, RemindableInterface {
    use s00d\Permissions\Can;

Usage

Create a new role:, (*7)

$role = new \s00d\Permissions\Role();
$role->name = 'Administrator';
$role->save();

Create a new permission:, (*8)

$permission = new \s00d\Permissions\Permission();
$permission->name = 'read_articles';
$permission->display_name ='Can read articles';
$permission->save();

Attach the permission to the role:, (*9)

$role->allow($permission);

Create a user:, (*10)

$user = new User;
$user->role_id = 1;
$user->save();

And you're set! To check if a user has a permission:, (*11)

$user = User::find(1);

if ($user->can('read_articles'))
    echo 'The user with the ID of "1" can read articles';

To check if the current authenticated user has a permission:, (*12)

if (Auth::user()->can('read_articles'))
    echo 'The current authenticated user can read articles';

The Versions

04/12 2015

dev-master

9999999-dev

Laravel 5 package for handling user roles and permissions.

  Sources   Download

MIT

The Requires

 

by Avatar s00d

laravel auth roles permissions