Generate default permissions for spatie permissions package according to your models
zakariajawas/permissions-generator is a Laravel package for generate default permissions for spatie permissions package according to your models.
It currently has 6 GitHub stars and 63 downloads on Packagist (latest version v0.0.6).
Install it with composer require zakariajawas/permissions-generator.
Discover more Laravel packages by zakariajawas
or browse all Laravel packages to compare alternatives.
Last updated
Generate basic permissions for spatie permissions package for all your models at once using one artisan command.
This package contains a GeneratePermissionsProvider that you can use in your packages to easily register the config file and the artisan command.
If you are using spatie permissions package, you need to create permissions for roles manually, common permissions for all models are access (list), create, edit and delete
This package will create all the basic permissions for all models using only one artisan command.
php artisan permissions:generate
If you have the following models [Category, Product] as example, after running the generate command, the following rows will be inserted in your permissions table
list category
create category
edit category
delete category
list product
create product
edit product
delete product
Note: You can modify some values inside the config file, check Working with config file section below.
composer require zakariajawas/permissions-generator
You should publish the config/permissionsgenerator.php config file with:
php artisan vendor:publish --provider="ZakariaJawas\PermissionsGenerator\Providers\GeneratePermissionsProvider"
In config/permissionsgenerator.php file you can modify the following values.
These are the basic permissions.
'permissions' => ['list', 'create', 'edit', 'delete']
For example to add access permission and change edit to update you can do this.
'permissions' => ['access', 'list', 'create', 'update', 'delete']
'exclude' => [
App\Models\Session::class, //no permissions generated for Session model
],
'staticPermissions' => ['export pdf', 'access dashboard']
Note:-
permission + model name, if you want to add a prefix you can specify it here.'prefix' => 'can',
Result will be can create product instead of create product
The MIT License (MIT). Please see License File for more information.
Zakaria Jawas @zakariajawas
If you spot a problem you can open an issue on the Github page, or alternatively, you can contact me via [email protected]
Support the library by posting in
If you enjoy it, please make this library better :+1: