centrust / nova-modules
Nova Modular Architrchter
Requires
- php: ^8.1
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
This package provides a modular architecture for Laravel Nova, allowing you to organize your Nova resources, actions, policies, and more into dedicated modules. It helps keep your app/Nova directory clean and improves code maintainability by grouping related functionality.
Installation
You can install the package via composer:
composer require centrust/nova-modules
You can publish the config file with:
php artisan vendor:publish --tag="nova-modules-config"
Module Architecture
The package organizes modules under the app/Nova/Modules directory. Each module has its own subdirectory containing its specific components:
app/Nova/Modules/
└── YourModuleName/
├── Actions/
├── Enums/
├── Filters/
├── Lenses/
├── Metrics/
├── Policies/
├── Resources/
├── Rules/
└── Services/
Usage
The package provides several Artisan commands to generate modules and their components.
Create a New Module
To create the directory structure for a new module:
php artisan module:create
This command will ask for the module name and generate the standard directory structure.
Generate Module Components
You can generate specific components within a module using the following commands:
Create a Resource
php artisan module:resource
Prompts for: Module name, Resource name, and Model name.
Create an Action
php artisan module:action
Prompts for: Module name and Action name.
Create a Policy
php artisan module:policy
Prompts for: Module name, Policy name, and Model name. This generates a standard Laravel policy that applies to the Eloquent Model.
Create a Nova Policy
php artisan module:nova-policy
Prompts for: Module name, Policy name, and Resource class. This generates a Nova-specific policy where the resource itself is passed instead of the Model. This is specifically useful for Nova V5 where policies can be directly applied to resources. Like: public static $policy =nova-policy::class; inside the nova resource
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.