teikun-86 / laravel-modular
Laravel Modular Structure
Requires
- laravel/framework: ^10.0|^11.0|^12.0|^13.0
- lorisleiva/laravel-actions: ^2.9
Requires (Dev)
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
Laravel Modular is a package that helps you structure your Laravel application into modules. It provides commands to easily create and manage modules, keeping your codebase organized and scalable.
Installation
You can install the package via composer:
composer require teikun-86/laravel-modular
Configuration
You can publish the configuration file using the following artisan command:
php artisan vendor:publish --tag="modular-config"
This will create a config/modular.php file in your application where you can configure the base namespace for your modules:
return [ /* |------------------------------------------------------------ | Namespace Configuration |------------------------------------------------------------ | Base namespace for all generated modules. | Can be overridden by environment variable or module config. | Should usually match your application's root namespace. | Default: 'LaravelApp' | Example: 'LaravelApp', 'MyProject' | Example output: namespace LaravelApp\Modules\User\Models; |------------------------------------------------------------ */ 'namespace' => env('MODULAR_NAMESPACE', 'LaravelApp'), ];
Usage
Creating a Module
To create a new module, you can use the make:module artisan command:
php artisan make:module {name}
You can optionally pass a --namespace option:
php artisan make:module {name} --namespace="CustomNamespace"
This command will automatically:
- Create a new directory for your module under the application's
modules/path. - Set up the basic
src/directory. - Generate a ServiceProvider for the module.
- Add the ServiceProvider to your application's bootstrap providers file.
- Update your
composer.jsonto include the new module's PSR-4 autoloading rules and runcomposer dump-autoload.
Creating Module Classes
You can also create specific classes inside your modules (like ServiceProviders, Controllers, etc.) using the make:module-class command.
php artisan make:module-class --module={name} --type={type} {class_name}
License
The MIT License (MIT). Please see License File for more information.