Skip to content
Tortue Torche edited this page May 27, 2015 · 4 revisions

You will usually be working with four actions when defining and checking permissions: read, create, update, delete. These aren't the same as the 7 RESTful actions in Rails. AuthorityController automatically adds some convenient aliases for mapping the controller actions.

$this->$authority->addAlias('read', ['index', 'show']);
$this->$authority->addAlias('create', 'new');
$this->$authority->addAlias('update', 'edit');

Notice the edit action is aliased to update. This means if the user is able to update a record he also has permission to edit it. You can define your own aliases in the AuthorityController config.php file.

// config/authority-controller.php # For Laravel 5.0
// app/config/packages/efficiently/authority-controller/config.php # For Laravel 4.*

return [
    'initialize' => function ($authority) {
        $user = Auth::guest() ? new User : $authority->getCurrentUser();

        $authority->addAlias('modify', ['update', 'delete']);
        $authority->allow('modify', 'Comment');
    }
];

// in controller or view
Authority::can('update', 'Comment'); //-> true

You are not restricted to just the 7 RESTful actions, you can use any action name. See Custom Actions for details.

Please note that if you are changing the default aliasedActions, the original actions associated with the alias will NOT be removed. For example, following statement will not have any change on the alias :read, which points to show and index:

$authority->addAlias('read', 'show'); //this will have no change on the alias 'read'!

If you want to change the default actions, you should use clearAliasedActions() method to remove ALL default aliases first.