solarios/permission

Permissions for Laravel 5.6


License
MIT

Documentation

Solarios Permission

A very simple permission package for Laravel 5.6. Includes roles and permissions.

You can install the package via composer:

composer require solarios/permission

Because Laravel >= 5.5 uses auto-disover, the service provider will automatically register. If you want to include it manually, do so in the config/app.php file.

'providers' => [
    // ...
    Solarios\Permission\PermissionServiceProvider::class,
];

Usage

The packages comes with 2 traits:

  • HasPermissions
  • HasRoles

HasPermissions

The hasPermissionTo() method checks if the model has a permission. If the model also uses roles, it will also check the role for the permission.

$user->givePermissionTo('manage users');

$user->hasPermissionTo('manage users');
// Returns: true

Or when there is a role 'admin' with the 'manage users' permission:

$user->giveRole('admin');
// The admin role has the 'manage users' permission.

$role->hasPermissionTo('manage users');
// Returns: true

Remove a permission

$user->revokePermissionTo('manage users');

Hasroles

Use this trait to give a model roles.

$user->giveRole('editor');

$user->hasRole('editor');
// Returns: true

Remove a role

$user->revokeRole('editor');

Relations

Roles and permissions both have a polymorphic relation so we are not bound to one (user) model.