Change where modules live and their namespace
To store modules in app-modules/ under the AppModules root namespace, update paths.modules and namespace in config/modules.php, plus the merge-plugin glob in composer.json. Publish config/modules.php first if you have not already:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider" --tag=config-
Update the namespace and modules path in
config/modules.php.config/modules.php 'namespace' => 'AppModules','paths' => ['modules' => base_path('app-modules'),// ...], -
Update the
merge-pluginglob incomposer.jsonso Composer autoloads classes from the new folder.composer.json "extra": {"merge-plugin": {"include": ["app-modules/*/composer.json"]}} -
Rebuild the autoloader.
Terminal window composer dump-autoload -
Create a module and verify its location and namespace.
Terminal window php artisan module:make BlogThis creates
app-modules/Blog. Itscomposer.jsonmapsAppModules\Blog\toapp/, andmodule.jsonregistersAppModules\Blog\Providers\BlogServiceProvider.
Move modules that already exist
Section titled “Move modules that already exist”Config changes do not move or rewrite existing modules. Migrate each existing module manually:
-
Move the module folder.
Terminal window mkdir -p app-modulesmv Modules/Blog app-modules/Blog -
If you changed
namespace, replaceModules\Blog(and escapedModules\\Bloginmodule.jsonandcomposer.json) withAppModules\Blog. This command leavesNwidart\Modules\...untouched:Terminal window grep -rl 'Modules' app-modules/Blog | xargs perl -pi -e 's/(?<!\w)(?<!\w\\)Modules(\\{1,2})Blog\b/AppModules$1Blog/g' -
Update the
merge-pluginglob incomposer.jsonas above and runcomposer dump-autoload. -
Check the result.
Terminal window php artisan module:listBlogshowsapp-modules/Blogas its path. Its enabled status stays unchanged becausemodules_statuses.jsonis keyed by module name.
Update imports of the old namespace in your application code manually. module:composer-update does not rename namespaces; it only updates legacy Modules\<Name>\App\ PSR-4 entries.