Looking to hire Laravel developers? Try LaraJobs

laravel-module-support maintained by vbk-solutions

Description
Composer-installable module support for Laravel applications.
Last update
2026/07/13 00:58 (dev-main)
License
Links
Downloads
14

Comments
comments powered by Disqus

Laravel Module Support

Laravel Module Support helps you split a Laravel application into clear and independent modules.

The package can:

  • create modules
  • enable and disable modules
  • load module service providers
  • manage module dependencies
  • add features to existing modules
  • run tests for one module

Requirements

  • PHP 8.2 or newer
  • Laravel 11, 12 or 13

Installation

Step 1: Install the package

Run this command in your Laravel application:

composer require vbk-solutions/laravel-module-support

Laravel will discover the package service provider automatically.

Step 2: Publish the configuration

php artisan vendor:publish --tag=module-support-config

This creates:

config/modules.php

The default module directory is:

modules

Publishing the configuration is optional. Only publish it when you want to change the module path or status file.

Step 3: Add the module namespace

Open the main composer.json file of your Laravel application.

Add Modules\\ to autoload.psr-4:

{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "modules/"
    }
  }
}

Keep all namespaces that are already in your file.

Step 4: Refresh the autoloader

composer dump-autoload
php artisan optimize:clear

Step 5: Check the installation

php artisan module:help

You should now see all available module commands.

Commands

Command Description
php artisan module:create Blog Create a new module
php artisan module:add Blog Add features to an existing module
php artisan module:list Show all modules
php artisan module:status Blog Show information about one module
php artisan module:enable Blog Enable a module
php artisan module:disable Blog Disable a module
php artisan module:depends-on Blog Show which modules depend on a module
php artisan module:test Blog Run tests for one module
php artisan module:help Show package help

Show help for one command:

php artisan module:help add
php artisan module:help create
php artisan module:help test

Show detailed help for all commands:

php artisan module:help --all

Add features to a module

Open the feature menu:

php artisan module:add Blog

Or add features directly:

php artisan module:add Blog api-routes events migrations

Available features:

Feature Description
provider Add a module service provider
api-routes Add an API route file
web-routes Add a web route file
events Add event and listener support
migrations Add migration, seeder and factory directories
translations Add a translation directory
views Add a Blade view directory and example view
config Add a module configuration file
tests Add feature and unit test directories

Short feature names also work:

api, web, event, migration, translation, view, test

Existing files are not overwritten by default.

Use --force only when you want to replace generated feature files:

php artisan module:add Blog api-routes --force

Module structure

A module can look like this:

modules/Blog/
├── Config/
├── Database/
├── Events/
├── Listeners/
├── Providers/
├── Resources/
├── Routes/
├── Tests/
└── module.php

A module only needs the directories that it uses.

Module definition

Every module has a module.php file.

Example:

<?php

namespace Modules\Blog;

use Modules\Blog\Providers\BlogServiceProvider;
use VBKSolutions\LaravelModuleSupport\Data\ModuleDefinition;

return new ModuleDefinition(
    name: 'Blog',
    version: '1.0.0',
    description: 'Blog module',
    author: 'Your Name',
    dependencies: [],
    providers: [
        BlogServiceProvider::class,
    ],
);

Use dependencies when one module needs another module:

dependencies: [
    'Core',
    'Users',
],

The required modules must exist and be enabled before this module can be enabled.

Common problems

Module commands are missing

Run:

composer dump-autoload
php artisan package:discover
php artisan optimize:clear

Then check:

php artisan module:help

A module class cannot be found

Make sure the main composer.json file contains:

"Modules\\": "modules/"

Then run:

composer dump-autoload

A module cannot be enabled

Check the module status:

php artisan module:status Blog

Enable its required modules first.

License

MIT

Create your first module

This example creates a simple Blog module with an API route.

1. Create the module

php artisan module:create Blog

The command asks which features you want.

For a simple API module, choose:

Version: 1.0.0
Description: Blog module
Create a module service provider: yes
Create API routes: yes
Create web routes: no
Create migrations: no
Create tests: yes
Create translations: no
Create Blade views: no
Create module configuration: no
Create event support: no
Create disabled: no

The module is created in:

modules/Blog

2. Check the module

php artisan module:status Blog

The module should be enabled.

3. Open the API route

Open this path in your Laravel application:

/api/blog

You should receive the JSON response from the Blog module.

4. Add more features later

You do not need to create the module again.

For example:

php artisan module:add Blog events migrations views

Your first module is now ready for controllers, models, routes and business logic.