Skip to content

Generate basic permissions for spatie permissions package for all your models at once using one artisan command.

License

Notifications You must be signed in to change notification settings

ZakariaJawas/permissions-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Permissions Generator

Licence Stars

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.

What It Does

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.

Getting started

Installation

composer require zakariajawas/permissions-generator

You should publish the config/permissionsgenerator.php config file with:

php artisan vendor:publish --provider="ZakariaJawas\PermissionsGenerator\GeneratePermissionsProvider"

Working with config file

In config/permissionsgenerator.php file you can modify the following values.

  • Modify this value to add, update or delete a permission.

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']
  • By default the package will generate the permissions for all project models, you might want to exclude specific one or more models so you can do this.
'exclude' => [
App\Models\Session::class, //no permissions generated for Session model
],
  • If you have static permissions which are not related to models for example export to pdf or access all data or maybe a page which doesn't have a model you can add these permisisons in $staticPermissions array
'staticPermissions' => ['export pdf', 'access dashboard']

Note:-

  1. You have to add the full model class path.
  2. You don't have to exclude other packages models, this package won't create permissions for them.
  • Default permissions name is 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

License

The MIT License (MIT). Please see License File for more information.

Author

Zakaria Jawas @zakariajawas

Getting help

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 twitting in Twitter

If you enjoy it, please make this library better 👍

About

Generate basic permissions for spatie permissions package for all your models at once using one artisan command.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages