curly-deni / laravel-permission-maker
Laravel package to easily generate migration files for CRUD and single permissions based on spatie/laravel-permission.
Fund package maintenance!
curly-deni
Requires
- php: ^8.0
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
- spatie/laravel-permission: ^6.17
Requires (Dev)
- laravel/pint: ^1.14
README
Laravel Permission Maker is a simple extension for spatie/laravel-permission that automates the creation of permission migrations.
Quickly generate full CRUD permission sets or individual permissions using Artisan commands.
Features
- 🔥 Quickly scaffold CRUD permissions for any resource.
- ✍️ Generate a migration for a single permission with one command.
- 📦 Seamlessly integrates with spatie/laravel-permission.
- 🚀 Clean, minimalistic, and developer-friendly.
- 🛠️ Fully customizable stub templates for advanced use cases.
Installation
Install the package via Composer:
composer require curly-deni/laravel-permission-maker
Publish the configuration file:
php artisan vendor:publish --tag="permission-maker-config"
Ensure that the Spatie permission migrations are published and migrated:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="permission-migrations" php artisan migrate
Configuration
The configuration file allows you to control which CRUD permissions are automatically generated when using the permission:commit-crud
command.
Default configuration (config/permission-maker.php
):
<?php return [ 'create' => [ 'generate' => true, ], 'read' => [ 'generate' => false, ], 'update' => [ 'generate' => true, ], 'delete' => [ 'generate' => true, ], ];
Options
-
create.generate
:
Should thecreate
permission be generated?
Default:true
-
read.generate
:
Should theread
permission be generated?
Default:false
-
update.generate
:
Should theupdate
permission be generated?
Default:true
-
delete.generate
:
Should thedelete
permission be generated?
Default:true
You can adjust these options according to your needs by modifying the published configuration file.
Usage
Command | Description | Options |
---|---|---|
permission:commit-crud {resource} |
Create a migration for CRUD permissions | --private , --own |
permission:commit {name} |
Create a migration for a single permission | None |
1. permission:commit-crud
Generates a set of standard CRUD permissions (create
, update
, delete
, read
) for a specified resource.
php artisan permission:commit-crud {resource} {--private} {--own}
Argument / Option | Description |
---|---|
resource |
The name of the resource (preferably in snake_case ). |
--private |
Add a private_read permission. |
--own |
Add "own" permissions: own_read , own_update , own_delete . |
Example:
php artisan permission:commit-crud blog_post --private --own
Generated permissions:
blog_post:create
blog_post:update
blog_post:delete
blog_post:read
blog_post:private_read
blog_post:own_read
blog_post:own_update
blog_post:own_delete
2. permission:commit
Generates a migration for a single, custom permission.
php artisan permission:commit {name}
Argument | Description |
---|---|
name |
The name of the permission (e.g., post:publish ). |
Example:
php artisan permission:commit post:publish
Generated permission:
post:publish
Credits
License
The MIT License (MIT).
Please see License File for more information.