2017 © Pedro Peláez
 

library permissions

Tiny Laravel 4 package for handling user roles and permissions.

image

mrterryh/permissions

Tiny Laravel 4 package for handling user roles and permissions.

  • Wednesday, February 1, 2017
  • by mrterryh
  • Repository
  • 3 Watchers
  • 59 Stars
  • 86 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

IMPORTANT!

This package is outdated and no longer maintained. I plan on bringing it back up to date eventually, but until then there are plenty of decent alternatives., (*1)

Permissions

Tiny Laravel 4 package for handling user roles and permissions., (*2)

Installation

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

"mrterryh/permissions": "dev-master"

Run $ composer update., (*4)

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

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

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

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

Usage

Create a new role:, (*8)

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

Create a new permission:, (*9)

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

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

$role->allow($permission);

Create a user:, (*11)

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

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

$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:, (*13)

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

License

Permissions is licensed under the MIT license., (*14)

Thank you!

Thank you for using my package. Should you encouter any problems, please submit them here and they shall be dealt with promptly., (*15)

The Versions

01/02 2017

dev-master

9999999-dev

Tiny Laravel 4 package for handling user roles and permissions.

  Sources   Download

MIT

The Requires

 

by Terry Harvey

laravel auth roles permissions