marcogeorge7 / permission-generator
Generate json file with all permission that call in controllers and views
Requires
- php: ^7.4|^8.0
- ext-json: *
- laravel/framework: >=5.4.0
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.0
- slevomat/coding-standard: ^6.0
README
permission-generator scans your project resources/view/
and app/
folder to find @can(...)
, Gate::allow(...)
functions, then it create keys based on first parameter value and insert into json permission file.
Installation
You just have to require the package
$ composer require marcogeorge7/permission-generator
This package register the provider automatically, See laravel package discover.
Usage
First you have to create json files in resource to save permission in it:
app/
resources/
role/
permissions.json
second, publish the configuration file.
php artisan vendor:publish --provider="PermissionGenerator\Framework\GeneratorServiceProvider"
Output
generator:update
command will scan your code to identify new permission keys, then it'll update json file on app/resources/role/
folder appending this keys.
{ "access_index": "can access all", "create_user": "can create user", "update_user": "" }
if for any reason artisan can't find generator:update
command, you can register the provider manually on your config/app.php
file:
return [ ... 'providers' => [ ... PermissionGenerator\Framework\GeneratorServiceProvider::class, ... ] ]
Customization
You can change the default path of views to scan and the output of the json permission file.
Todo
- auto create value as a description of permission in json object
- insert permission in database table permission as defult and can replace it with config file