Looking to hire Laravel developers? Try LaraJobs

laravel-modular maintained by teikun-86

Description
Laravel Modular Structure
Last update
2026/07/17 17:45 (dev-main)
License
Links
Downloads
66

Comments
comments powered by Disqus

Laravel Modular

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:

  1. Create a new directory for your module under the application's modules/ path.
  2. Set up the basic src/ directory.
  3. Generate a ServiceProvider for the module.
  4. Add the ServiceProvider to your application's bootstrap providers file.
  5. Update your composer.json to include the new module's PSR-4 autoloading rules and run composer 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.