2017 © Pedro Peláez
 

package permissions

An easy permissions for Laravel 5.

image

tadeas-j/permissions

An easy permissions for Laravel 5.

  • Thursday, April 9, 2015
  • by TadeasJ
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Permissions

An easy Laravel 5 permissions package., (*1)

Installation via Composer

require : {
  "tadeas-j/permissions": "dev-master"
}

Next, what you need to do is to run., (*2)

composer update

Now, you have successfully installed the package., (*3)

Next required step is to add package's service provider to laravel application config, which is located in 'app/config/app.php'., (*4)

'Permissions' => 'Permissions\Providers\PermissionsProvider'

And lastly for configuring our permissions and roles we need to publish 'config.php' file to '/config/permissions/config.php'., (*5)

php artisan vendor:publish

(Optional) Using package's facade

I highly recommend u to use package's prepared facade, only thing, what you need to do, is to register it in 'app/config/app.php'., (*6)

'Permissions' => 'Permissions\Facades\Permissions'

(Important) Configuration

Configuration file should be published to '/config/permissions/config.php'. If you missed it, you can do it easilly with calling this command., (*7)

php artisan vendor:publish

At first, you need to put 'role' column to your users table. Default 'config.php' file looks like this., (*8)

$aliases = array(
    'manage' => ['create', 'delete', 'edit']
);

$roles = array(
    'admin' => [
        'manage.users',
    ]
);

This means, that role 'admin' is allowed to manage.users, 'manage' is alias to 'create', 'delete' and 'edit'. So it is the same like this., (*9)

$aliases = array();

$roles = array(
    'admin' => [
        'create.users',
        'delete.users',
        'edit.users',
    ]
);

Using package

So let's think about, that we have got one user with role 'admin', 'admin' role is allowed for 'create.users', and the code below is exactly, what we need to do in our creating proccess., (*10)

Permissions::can('create.users');

This will get our logged user, his permissions and then it will check them. If we want to check permissions of user with ID 1 for example, we will just easilly do this., (*11)

Permissions::can('create.users', User::find(1));

There is also a trait, what you can use., (*12)

Permissions\PermissionsTrait

After using this trait in your user model, you will be allowed to do something like this., (*13)

Auth::user()->can('create.users');

The Versions

09/04 2015

dev-master

9999999-dev https://github.com/tadeas-j/permissions

An easy permissions for Laravel 5.

  Sources   Download

laravel permissions