awema-pl/module-permission

v1.0.5 2020-11-25 22:34 UTC

This package is auto-updated.

Last update: 2024-10-15 01:03:55 UTC


README

Coverage report Build status Composer Ready Downloads Last version

PHP Roles & Permissions package. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require awema-pl/module-permission

The package will automatically register itself.

You can publish migration with:

php artisan vendor:publish --provider="AwemaPL\Permission\PermissionServiceProvider" --tag="migrations"

After migration has been published you can create tables by running:

php artisan migrate

You can publish package views:

php artisan vendor:publish --provider="AwemaPL\Permission\PermissionServiceProvider" --tag="views"

Run seeder for roles and permissions tables:

php artisan db:seed --class="AwemaPL\Permission\Seeds\PermissionTablesSeeder"

Configuration

You can set up routes path and naming prefixes. First publish config:

php artisan vendor:publish --provider="AwemaPL\Permission\PermissionServiceProvider" --tag="config"
'routes' => [
    // roles routes prefixes (path & naming)
    'roles_prefix' => 'roles',
    'roles_name_prefix' => 'roles.',

    // permissions routes prefixes
    'permissions_prefix' => 'permissions',
    'permissions_name_prefix' => 'permissions.',
]

Usage

Add to routes/web.php

Permission::routes();

Package will register several routes:

+--------+----------+--------------------+--------------------+-----------------------------------------------------------+------------+
| Domain | Method   | URI                | Name               | Action                                                    | Middleware |
+--------+----------+--------------------+--------------------+-----------------------------------------------------------+------------+
|        | GET|HEAD | permissions        | permissions.index  | AwemaPL\Permission\Controllers\PermissionController@index  | web        |
|        | POST     | permissions        | permissions.store  | AwemaPL\Permission\Controllers\PermissionController@store  | web        |
|        | POST     | permissions/assign | permissions.assign | AwemaPL\Permission\Controllers\PermissionController@assign | web        |
|        | POST     | permissions/revoke | permissions.revoke | AwemaPL\Permission\Controllers\PermissionController@revoke | web        |
|        | GET|HEAD | roles              | roles.index        | AwemaPL\Permission\Controllers\RoleController@index        | web        |
|        | POST     | roles              | roles.store        | AwemaPL\Permission\Controllers\RoleController@store        | web        |
|        | POST     | roles/assign       | roles.assign       | AwemaPL\Permission\Controllers\RoleController@assign       | web        |
|        | POST     | roles/revoke       | roles.revoke       | AwemaPL\Permission\Controllers\RoleController@revoke       | web        |
+--------+----------+--------------------+--------------------+-----------------------------------------------------------+------------+
# Routes for permissions management
'permissions.'

# Routes for roles management
'roles.'

Add AwemaPL\Permission\Traits\HasRoles trait to your User model(s):

use AwemaPL\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

Testing

You can run the tests with:

composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email :author_email instead of using the issue tracker.

Credits

License

GNU General Public License v3.0. Please see the license file for more information.