Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Working with roles and permissions

Voydz edited this page Dec 14, 2015 · 5 revisions

Working with roles and permissions

Table of Contents

  1. Integration
  2. Providing own permissions
  3. Use permissions
  4. Check for access
  5. Relevant links

Integration

The whole auth and security implementation is done with the help of Laravel's authorization package. The persistence layer is written by ourselves. On top of this Vain provides another ServiceProvider (AuthServiceProvider) inside the user module which registers all stored roles and permissions for you, to make working with auth and security as convenient as possible.

Providing own permissions

If your module should provide its own permissions in the application permissions pool it has to register a new config file with only an array of the permission keys. Also, be sure to document it well. Here is an example taken out of the user´s permission.php config file:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | User Permissions
    |--------------------------------------------------------------------------
    |
    | These permissions handle the access to the user resources. These are
    | generally considered static, so if you change them you can not expect
    | the app to work properly.
    |
    */

    'user.users.show',
    'user.users.edit',
    'user.users.destroy',

...

The registration of the config file can normally be done within a ServiceProvider. This code was taken from the ConfigServiceProvider of the user module. The config file itself has to be merged into the permission namespace like so:

    public function register()
    {
        $this->mergeConfigFrom(
            __DIR__.'/../Config/permission.php', 'permission'
        );

...

NOTE: For more information about naming conventions, see the naming conventions article in this wiki.

Use permissions

Check for access

Grab a user object in any possibility which suits your current context best. You can follow the sentinel docu step by step as written here to check permissions and check roles.

Relevant links