victormgomes / laravel-modules-plus
Enhancements for the nWidart/laravel-modules package
Package info
github.com/VictorMGomes/laravel-modules-plus
pkg:composer/victormgomes/laravel-modules-plus
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/auth: ^11.0||^12.0||^13.0
- illuminate/console: ^11.0||^12.0||^13.0
- illuminate/contracts: ^11.0||^12.0||^13.0
- illuminate/database: ^11.0||^12.0||^13.0
- illuminate/events: ^11.0||^12.0||^13.0
- illuminate/filesystem: ^11.0||^12.0||^13.0
- illuminate/http: ^11.0||^12.0||^13.0
- illuminate/support: ^11.0||^12.0||^13.0
- illuminate/view: ^11.0||^12.0||^13.0
- nwidart/laravel-modules: ^13.0
- spatie/laravel-package-tools: ^1.16
- symfony/finder: ^7.0|^8.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
README
The Plug-and-Play Engine for Laravel Modules.
Introduction
Laravel Modules Plus is a zero-configuration enhancement designed to transform your modules into truly self-contained, autonomous units. By extending the provided AbstractModuleServiceProvider, your modules instantly become Plug-and-Play: they automatically handle their own resource registration, factory resolution, and data seeding without any manual boilerplate in the main application.
Why use this package?
- Module Autonomy: Modules become self-configuring "mini-packages". Drop a module into any project, and its logic is instantly alive.
- Standardized Structure: Enforces a clean, consistent convention across all modules, making your codebase predictable and enterprise-ready.
- Zero-Config Discovery: Automatic registration of Routes, Policies, Observers, and Events based on simple folder conventions.
- Agnostic Factory Resolution: Automatically resolves Eloquent factories for modular models. Keep your models clean and free of package-specific traits.
- Dynamic Seeding: Effortlessly manage data population with helpers that discover seeders across your entire modular ecosystem.
- Full Command Integration: All original
nWidart/laravel-modulescommands are fully supported and aware of the Environment Control patch. - AI-Enhanced Development: Includes a built-in Laravel Boost Skill to help AI agents build and maintain your modules correctly.
- Contextual Flexibility: Optionally separate resources (Migrations, Seeders) into specific contexts like
TenantorCentralfor complex architectures.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by sponsoring us on GitHub.
Installation
- Install the package via composer:
composer require victormgomes/laravel-modules-plus
- (Optional) Publish the configuration and stubs:
php artisan modules-plus:install
- Update your
config/modules.phpto use the new Activator:
'activator' => 'env', 'activators' => [ 'env' => [ 'class' => \Victormgomes\ModulesPlus\Activators\EnvActivator::class, ], ],
Usage
1. Activating Modules
Manage module activation directly via your .env file, keeping your modules_statuses.json out of version control:
APP_MODULES_ENABLED=Auth,User,Chat,Billing
All standard commands (e.g., php artisan module:list, module:migrate) will respect this setting automatically. Commands like php artisan module:enable {name} will now update your .env file directly.
2. Standard Plug-and-Play Structure
By extending AbstractModuleServiceProvider, the following resources are discovered and registered automatically (respecting any custom paths defined in your modules.php configuration):
- Routes:
routes/api.phpandroutes/web.phpare loaded with standard middleware. - Config: Automatically merges
{module}/config/{module}.phpinto the global configuration. - Views: Loads views from
resources/views/using the{module}::namespace. - Translations: Loads lang files from
resources/lang/(including JSON). - Migrations: All migrations in
database/migrations/are loaded by default. - Factories: Factories in
database/factories/are automatically resolved for modular models. - Seeders: All seeders in
database/seeders/can be dynamically retrieved for seeding. - Policies:
app/Policies/UserPolicy.phpis automatically linked toapp/Models/User.php. - Observers:
app/Observers/UserObserver.phpis automatically linked toapp/Models/User.php. - Events/Listeners: Automatically discovers listeners in the
app/Listeners/directory. - Console Commands: Automatically registers all commands in
app/Console/Commands/. - View Components: Registers components in
app/View/Components/. - Livewire: Automatically registers components in the
Livewire/directory.
3. Contextual Discovery (Advanced)
For more complex architectures (like Multi-Tenancy), the package allows you to silo resources into sub-contexts:
- Contextual Migrations: Place migrations in
database/migrations/Tenantto load them only in specific database contexts. - Contextual Seeders: Use subfolders like
database/seeders/Tenant/and retrieve them using theSeederPathshelper:
use Victormgomes\ModulesPlus\Support\SeederPaths; use Victormgomes\ModulesPlus\Support\TenantSeeders; // Get seeders for any custom context $seeders = SeederPaths::get('MyContext'); // Or use the built-in Tenant helper $seeders = TenantSeeders::getSeeders(); $this->call($seeders);
AI Agent Integration (Laravel Boost)
This package includes a dedicated Laravel Boost Skill. When installed, it helps AI agents (like Gemini CLI, Cursor, or Claude) understand the modular architecture, respect folder conventions, and generate correct plug-and-play code.
To install the skill in your project:
php artisan boost:install
Then select victormgomes/laravel-modules-plus from the third-party skills list.
Configuration
After publishing the configuration via php artisan modules-plus:install, you can customize the following in config/modules-plus.php:
custom_stubs: When enabled, the package uses internal optimized stubs that follow theAbstractModuleServiceProviderpattern.paths: Define additional folder conventions for resource discovery that are not present in the defaultnWidart/laravel-modulesconfiguration.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.