Appearance
Generate Permissions Command
The mm:generate-permissions
command is used to generate permissions for models in a specific module.
Usage
bash
php artisan mm:generate-permissions [options]
Options
Option | Description |
---|---|
--module=MODULE | The specific module to generate permissions for |
--model=MODEL | The specific models to generate permissions for (can be used multiple times) |
Description
This command generates permissions for models within a module based on the configuration defined in config('module-manager.permissions')
. If you have multi-tenancy enabled, it will create permissions that respect the teams structure of the Spatie Permission package.
When executed, this command performs the following actions:
Select Module: If no module is specified, it asks you to select one from the enabled modules.
Select Models: Displays all models in the selected module and allows you to choose which ones to generate permissions for. You can select individual models or choose "All Models".
Generate Permissions: Creates permissions for each selected model based on the predefined actions in your configuration (e.g., viewAny, view, create, update, delete, etc.).
Clear Permission Cache: Updates the permission cache after creating new permissions.
Examples
Interactive Mode
bash
$ php artisan mm:generate-permissions
Generating permissions for models...
Select module to generate permissions for:
> Blog
Select models to generate permissions for in Blog module:
> All Models
> Post
> Comment
> Category
Generating permissions...
Created 10 permissions for model Post
Created 10 permissions for model Comment
Created 10 permissions for model Category
Permission cache updated
Process completed! 3 models had permissions generated, 0 skipped.
With Options
bash
$ php artisan mm:generate-permissions --module=Blog --model=Post --model=Comment
Generating permissions for models...
Generating permissions...
Created 10 permissions for model Post
Created 10 permissions for model Comment
Permission cache updated
Process completed! 2 models had permissions generated, 0 skipped.
Multi-tenant Support
When multi-tenancy is enabled in your configuration (module-manager.multi_tenancy
is set to true
), the permissions are created with support for teams structure, allowing you to assign permissions to specific tenants.
Notes
- This command is typically used when setting up a new module or adding new models that require permission control.
- The command is integrated with the module installation process, allowing you to generate permissions during module installation.
- When a module is removed, related permissions are automatically removed.