mouhamedfd/permissions-generator

:permission generation for all your declared routes with corresponding controller action

1.0.4 2024-10-30 12:53 UTC

This package is auto-updated.

Last update: 2024-10-30 13:20:41 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

This package add some artisan command to help generating permissions for your declared routes.

For the permissions management this package use Laravel-permission by Spatie

Usage

Each of your routes that you want to add permission should have an alias (name) seperated by dot(.) for exemple:

Route::get('/posts/special_action',[App\Http\Controllers\PostController::class, 'specialaction'])->name('posts.specialaction');
Route::get('/posts/another_action',[App\Http\Controllers\PostController::class, 'anotheraction'])->name('posts.anotheraction');

In this example permissions will be generated for the PostController linked to the specialaction and anotheraction

public function __construct()//#
{
    $this->middleware('auth');
    $this->middleware(['permission:posts.specialaction'])->only(['specialaction']);
    $this->middleware(['permission:posts.anotheraction'])->only(['anotheraction']);
        
 }//#

Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require mouhamedfd/permissions-generator

Publish configuration

php artisan vendor:publish --tag=permissions-generator.config

The default configuration exclude some keywords and some columns, it's also possible to add some middlewares

return [
    'excluded_keywords'=>[
        'Auth',
        'Translation',
    ],
    'have_resource_column'=>false,
    'have_description_column'=>false,
    'middlewares'=>[
        'auth',
    ],

];

Usage

Simulation mode

php artisan permission:generate

Database mode

php artisan permission:generate --action=database

Insertion to controllers

php artisan permission:generate --action=controllers

Change log

Please see the changelog for more information on what has changed recently.

Testing PHPUnit

git clone https://github.com/mouhamedfd/permissions-generator.git
composer install
cp vendor/spatie/laravel-permission/config/permission.php vendor/orchestra/testbench-core/laravel/config/permission.php
vendor/bin/testbench cache:clear
vendor/bin/testbench config:clear
composer exec phpunit [or vendor/bin/phpunit]

Contributing

Please see contributing.md for details and a todolist.

Credits

License

MIT. Please see the license file for more information.