# Configuration

On this page

You can publish the package configuration using the following command:

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"

In the published configuration file you can configure the following things:

Default namespace

What the default namespace will be when generating modules.

Default: Modules

The default namespace is set as Modules this will apply the namespace for all classes the module will use when it's being created and later when generation additional classes.

Overwrite the generated files (stubs)

Overwrite the default generated stubs to be used when generating modules. This can be useful to customise the output of different files.

These stubs set options and paths.

Enabled true or false will enable or disable a module upon creation, the default is false meaning you will have to enable a module manually.

To enable a module edit module_statuses.json or run the command:

php artisan module:enable ModuleName

note the module_statues.json file will be created if it does not exist using this command.

The contents of module_statuses.json looks like:

{
    "Users": true
}

The above would be when there is a single module called Users and is enabled.

Path points to a vendor directly where the default stubs are located, these can be published and modified.

Files set the file locations defaults.

Replacements is a way to do a Find and Replace on generation any matches will be replaced.

Comment out any files below that you do not want to be generated.

For example if you do not intend to use any frontend assets there is no need for CSS/JS files or asset loading files so turn them off:

'files' => [
    'routes/web' => 'routes/web.php',
    'routes/api' => 'routes/api.php',
    'views/index' => 'resources/views/index.blade.php',
    'views/master' => 'resources/views/layouts/master.blade.php',
    'scaffold/config' => 'config/config.php',
    'composer' => 'composer.json',
    //'assets/js/app' => 'resources/js/app.js',
    //'assets/sass/app' => 'resources/css/app.css',
    //'vite' => 'vite.config.js',
    //'package' => 'package.json',
],

The complete list:

'stubs' => [
    'enabled' => false,
    'path' => base_path('vendor/nwidart/laravel-modules/src/Commands/stubs'),
    'files' => [
        'routes/web' => 'routes/web.php',
        'routes/api' => 'routes/api.php',
        'views/index' => 'resources/views/index.blade.php',
        'views/master' => 'resources/views/layouts/master.blade.php',
        'scaffold/config' => 'config/config.php',
        'composer' => 'composer.json',
        'assets/js/app' => 'resources/assets/js/app.js',
        'assets/sass/app' => 'resources/assets/sass/app.scss',
        'vite' => 'vite.config.js',
        'package' => 'package.json',
    ],
    'replacements' => [
        'routes/web' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'CONTROLLER_NAMESPACE'],
        'routes/api' => ['LOWER_NAME', 'STUDLY_NAME'],
        'vite' => ['LOWER_NAME'],
        'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE'],
        'views/index' => ['LOWER_NAME'],
        'views/master' => ['LOWER_NAME', 'STUDLY_NAME'],
        'scaffold/config' => ['STUDLY_NAME'],
        'composer' => [
            'LOWER_NAME',
            'STUDLY_NAME',
            'VENDOR',
            'AUTHOR_NAME',
            'AUTHOR_EMAIL',
            'MODULE_NAMESPACE',
            'PROVIDER_NAMESPACE',
        ],
    ],
    'gitkeep' => true,
],

Generator Path

These are the files that are generated by default where generate is set to true, when false is used that path is not generated.

'generator' => [
    'config' => ['path' => 'config', 'generate' => true],
    'command' => ['path' => 'app/Console', 'generate' => false],
    'channels' => ['path' => 'app/Broadcasting', 'generate' => false],
    'migration' => ['path' => 'database/migrations', 'generate' => true],
    'seeder' => [
        'path' => 'database/seeders',
        'namespace' => 'database/seeders',
        'generate' => true,
    ],
    'factory' => ['path' => 'database/factories', 'generate' => true],
    'model' => ['path' => 'app/Models', 'generate' => true],
    'observer' => ['path' => 'app/Observers', 'generate' => false],
    'routes' => ['path' => 'routes', 'generate' => true],
    'controller' => ['path' => 'app/Http/Controllers', 'generate' => true],
    'filter' => ['path' => 'app/Http/Middleware', 'generate' => true],
    'request' => ['path' => 'app/Http/Requests', 'generate' => true],
    'provider' => ['path' => 'app/Providers', 'generate' => true],
    'assets' => ['path' => 'resources/assets', 'generate' => true],
    'lang' => ['path' => 'lang', 'generate' => true],
    'views' => ['path' => 'resources/views', 'generate' => true],
    'test' => ['path' => 'tests/Unit', 'generate' => true],
    'test-feature' => ['path' => 'tests/Feature', 'generate' => true],
    'repository' => ['path' => 'app/Repositories', 'generate' => false],
    'event' => ['path' => 'app/Events', 'generate' => false],
    'listener' => ['path' => 'app/Listeners', 'generate' => false],
    'policies' => ['path' => 'app/Policies', 'generate' => false],
    'rules' => ['path' => 'app/Rules', 'generate' => false],
    'jobs' => ['path' => 'app/Jobs', 'generate' => false],
    'emails' => ['path' => 'app/Emails', 'generate' => false],
    'notifications' => ['path' => 'app/Notifications', 'generate' => false],
    'resource' => ['path' => 'app/Resources', 'generate' => false],
    'component-view' => ['path' => 'resources/views/components', 'generate' => false],
    'component-class' => ['path' => 'app/View/Components', 'generate' => false],
]

Don't like Entities for the Models here's where you can change the path to Models instead.

Instead of Entities:

'model' => ['path' => 'Entities', 'generate' => true],

Use of Models:

'model' => ['path' => 'Models', 'generate' => true],

Package Commands

The commands you can run is determined from this list. Any commands you don't want to use can be commented out / removed from this list and will not then be available when running php artisan.

'commands' => [
    Commands\CommandMakeCommand::class,
    Commands\ComponentClassMakeCommand::class,
    Commands\ComponentViewMakeCommand::class,
    Commands\ControllerMakeCommand::class,
    Commands\DisableCommand::class,
    Commands\DumpCommand::class,
    Commands\EnableCommand::class,
    Commands\EventMakeCommand::class,
    Commands\JobMakeCommand::class,
    Commands\ListenerMakeCommand::class,
    Commands\MailMakeCommand::class,
    Commands\MiddlewareMakeCommand::class,
    Commands\NotificationMakeCommand::class,
    Commands\ProviderMakeCommand::class,
    Commands\RouteProviderMakeCommand::class,
    Commands\InstallCommand::class,
    Commands\ListCommand::class,
    Commands\ModuleDeleteCommand::class,
    Commands\ModuleMakeCommand::class,
    Commands\FactoryMakeCommand::class,
    Commands\PolicyMakeCommand::class,
    Commands\RequestMakeCommand::class,
    Commands\RuleMakeCommand::class,
    Commands\MigrateCommand::class,
    Commands\MigrateRefreshCommand::class,
    Commands\MigrateResetCommand::class,
    Commands\MigrateRollbackCommand::class,
    Commands\MigrateStatusCommand::class,
    Commands\MigrationMakeCommand::class,
    Commands\ModelMakeCommand::class,
    Commands\PublishCommand::class,
    Commands\PublishConfigurationCommand::class,
    Commands\PublishMigrationCommand::class,
    Commands\PublishTranslationCommand::class,
    Commands\SeedCommand::class,
    Commands\SeedMakeCommand::class,
    Commands\SetupCommand::class,
    Commands\UnUseCommand::class,
    Commands\UpdateCommand::class,
    Commands\UseCommand::class,
    Commands\ResourceMakeCommand::class,
    Commands\TestMakeCommand::class,
    Commands\LaravelModulesV6Migrator::class,
    Commands\ComponentClassMakeCommand::class,
    Commands\ComponentViewMakeCommand::class,
],

As from v10.0.5 the commands are loaded by an internal ConsoleServiceProvider.

For existing configs with the above list. Can be replaced with:

'commands' => ConsoleServiceProvider::defaultCommands()
    ->merge([
        // New commands go here
    ])->toArray(),

Overwrite the paths

Overwrite the default paths used throughout the package.

Set the path for where to place the Modules folder, where the assets will be published and the location for the migrations.

It's recommend keep the defaults here.

'paths' => [
    'modules' => base_path('Modules'),
    'assets' => public_path('modules'),
    'migration' => base_path('database/migrations'),

Scan additional folders for modules

By default, modules are loaded from a directory called Modules, in addition to the scan path. Any packages installed for modules can be loaded from here.

'scan' => [
    'enabled' => false,
    'paths' => [
        base_path('vendor/*/*'),
    ],
],

You can add your own locations for instance say you're building a large application and want to have multiple module folder locations, you can create as many as needed.

'scan' => [
    'enabled' => true,
    'paths' => [
        base_path('ModulesCms'),
        base_path('ModulesERP'),
        base_path('ModulesShop'),
    ],
],

Remember to set enabled to true to enable these locations.

Composer file template

When generating a module the composer.json file will contain the author details as set out below, change them as needed.

Take special notice of the vendor, if you plan on extracting modules to packages later it's recommend using your BitBucket/GitHub/GitLab vendor name here.

'composer' => [
    'vendor' => 'nwidart',
    'author' => [
        'name' => 'Nicolas Widart',
        'email' => 'n.widart@gmail.com',
    ],
]

Caching

If you have many modules it's a good idea to cache this information (like the multiple module.json files for example).

Modules can be cached, by default caching is off.

'cache' => [
    'enabled' => false,
    'driver' => 'file',
    'key' => 'laravel-modules',
    'lifetime' => 60,
],

Registering custom namespace

Decide which custom namespaces need to be registered by the package. If one is set to false, the package won't handle its registration.


Laravel Package built by Nicolas Widart.
Maintained by David Carr follow on X @dcblogdev