This package offers you the simplest way to organize your Laravel code into modules. Each module is a separate directory that contains all the necessary files for a complete Laravel package. We have tried as much as possible to use or extend the existing laravel commands and structures to offer the same rich features that Laravel continues to ship, and make it easier to maintain the package as Laravel evolves.
- Laravel 11 or higher
- PHP 8.2 or higher
You can install the package via composer:
composer require savannabits/modular
Once the package is installed, run the following command to prepare your app for generation of modules:
php artisan modular:install
Follow the prompts to complete the installation.
This package offers several commands which allow you to generate standard Laravel files and classes in your modules.
However, first you have to generate a module using the following command:
php artisan modular:make ModuleName
The above command will generate a directory structure similar to that of a standard laravel App, with an additional service provider to allow registration of the module. The module is generated inside the /modules directory of your project. Additionally, the command will proceed to install the module as a symlinked local package in your composer file so that it can be autoloaded. This process may also be triggered by using the command
php artisan modular:activate ModuleName
Run the following command to activate a module:
php artisan modular:activate ModuleName
This command will symlink the module to the composer file and run composer dump-autoload to make the module available to the application.
Run the following command to deactivate a module:
php artisan modular:deactivate ModuleName
This command will remove the module from the composer file and run composer dump-autoload to remove the module from the application.
To generate a controller in a module, run the following command and follow the prompts:
php artisan modular:make-controller
To generate a model in a module, run the following command and follow the prompts:
php artisan modular:make-model
To generate a migration in a module, run the following command and follow the prompts:
php artisan modular:make-migration
To generate a factory in a module, run the following command and follow the prompts:
php artisan modular:make-factory
To generate a seeder in a module, run the following command and follow the prompts:
php artisan modular:make-seeder
To generate a policy in a module, run the following command and follow the prompts:
php artisan modular:make-policy
To generate a request in a module, run the following command and follow the prompts:
php artisan modular:make-request
To generate a resource in a module, run the following command and follow the prompts:
php artisan modular:make-resource
To generate a test in a module, run the following command and follow the prompts:
php artisan modular:make-test
To generate a job in a module, run the following command and follow the prompts:
php artisan modular:make-job
To generate a console command in a module, run the following command and follow the prompts:
php artisan modular:make-command
To generate a provider in a module, run the following command and follow the prompts:
php artisan modular:make-provider
To generate a view in a module, run the following command and follow the prompts:
php artisan modular:make-view
The package also offers a few helper functions to make it easier to work with modules.
To get all modules in the application, you can use the following helper function:
use Savannabits\Modular\Facades\Modular;
$modules = Modular::allModules();
The above code will return a collection of instances of the Savannabits\Modular\Module
class for all active modules in
the app.
To get a specific module in the application, you can use the following helper function:
use Savannabits\Modular\Facades\Modular;
$module = Modular::module('ModuleName');
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.