Tiny Laravel 4 package for handling user roles and permissions.
PHP
Switch branches/tags
Nothing to show
Latest commit 569eca3 Feb 1, 2017 @mrterryh committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
public Initial commit Mar 3, 2014
src Added Role::deny() Mar 8, 2014
tests Initial commit Mar 3, 2014
README.md Update README.md Feb 1, 2017
composer.json Include licence Mar 5, 2014
composer.lock Initial commit Mar 3, 2014
phpunit.xml Initial commit Mar 3, 2014

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.

Permissions

Tiny Laravel 4 package for handling user roles and permissions.

Installation

Add the following to the require key of your composer.json file:

"mrterryh/permissions": "dev-master"

Run $ composer update.

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

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

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

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

Usage

Create a new role:

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

Create a new permission:

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

Attach the permission to the role:

$role->allow($permission);

Create a user:

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

And you're set! To check if a user has a permission:

$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:

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

License

Permissions is licensed under the MIT license.

Thank you!

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