Load modules from extra locations
To load modules stored outside paths.modules (for example in plugins/), add those folders to scan.paths. Each folder holds modules as subdirectories, such as plugins/Acme/module.json.
Scan extra folders from the config
Section titled “Scan extra folders from the config”-
Publish
config/modules.phpif you have not already.Terminal window php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider" --tag=config -
Enable scanning and list the extra folders.
config/modules.php 'scan' => ['enabled' => true,'paths' => [base_path('plugins'),],],The package appends
/*to any path that does not already end with/*, then looks formodule.jsoninside each match.base_path('plugins')matchesplugins/Acme/module.json, while the defaultbase_path('vendor/*/*')matchesvendor/acme/blog/module.json. -
Add the folder to
extra.merge-plugin.includeincomposer.jsonand rebuild the autoloader.composer.json "extra": {"merge-plugin": {"include": ["Modules/*/composer.json","plugins/*/composer.json"]}}Terminal window composer dump-autoloadAutoload the module before enabling it. Enabling a module whose provider class cannot autoload breaks every
artisancommand with a class-not-found error. -
Enable the discovered module. Newly scanned modules start disabled.
Terminal window php artisan module:enable Acme -
Check the result.
Terminal window php artisan module:listAcmeappears with its path (plugins/Acme [0]).
Add a folder at runtime
Section titled “Add a folder at runtime”Call Module::addLocation() to expose an extra folder at runtime:
use Nwidart\Modules\Facades\Module;
public function register(): void{ Module::addLocation(base_path('plugins'));}addLocation() makes modules visible to Module::all(), Module::find(), and module:list. It does not register their service providers, because module providers load before application providers run. Use scan.paths to boot providers from extra folders.