Installation
Requirements
- PHP 8.3+
- Laravel 11, 12 or 13
Install
composer require dem1-off/laravel-modularPublish the configuration:
php artisan vendor:publish --tag=modules-configThis writes config/modules.php. Its keys mirror the conventional module config (namespace, paths, statuses_file), so an existing modular project interoperates without editing any module.
Autoloading modules
Module classes need a PSR-4 mapping. Pick whichever fits — you don't have to turn modules into Composer packages.
Option A — just modules (default, zero setup)
Leave modules.autoload at its default (true). Each discovered module's namespace is registered at runtime, so a module works by just existing in the Modules/ directory:
php artisan make:module Blog # done — it autoloads and boots, no Composer changesNo package, no composer.json edits. This is the path if you simply want modules.
Option B — Composer path repository (promotion-ready)
If you might extract modules into standalone packages later, treat the modules directory as a path repository so each module is autoloaded from its own composer.json and benefits from an optimised classmap. Set modules.autoload => false, then:
// app composer.json
"repositories": [
{ "type": "path", "url": "Modules/*", "options": { "symlink": true } }
]composer require your-vendor/blog-module:@devPromotion is then zero-churn — swap the path entry for a VCS/registry entry. See Promote to a package.
Option C — root PSR-4
The classic approach: add each module's PSR-4 to the app's root composer.jsonautoload and composer dump-autoload. Set modules.autoload => false.
Set
modules.vendorinconfig/modules.phpto your vendor (e.g.acme) so generated modules are namedacme/blog-module.
Continue to Configuration.