Configuration
Every key in config/mod.php. Publish the file with:
php artisan vendor:publish --tag=mod-config
# -> config/mod.php| Key | Default | Description |
|---|---|---|
layout | 'laravel' | The active layout |
routes.order | [] | Modules loaded before the alphabetical remainder |
commands | true | Register the mod:* commands |
generators | [] | Replace the command behind a file type |
bases | null for each | The class DTOs, view models, value objects and actions extend |
bases_path | 'app/Support' | Where generated base classes go |
discovery.enabled | true | Turn discovery on or off |
discovery.file_types | [] | Discover more file types, or stop discovering one |
discovery.cache | 'bootstrap/cache/mod-discovery.php' | Where the discovery cache is written |
discovery.on_stale_cache | 'scan' | What happens when the cache is out of date |
discovery.factories | true | Find factories for models the layout places |
discovery.policies | true | Find policies for models the layout places |
layout
The active layout: a built-in name (laravel, modules, features, slices, type-first, ddd) or one you define with Mod::layout().
'layout' => 'modules',Layouts compares the built-in layouts.
commands
false registers no mod:* commands, for a host with its own Artisan commands. Placement and discovery keep working. The discovery cache commands are registered only while this and discovery.enabled are both on.
generators
The command class behind a file type, keyed by file type id. It replaces the built-in command, as Mod::generators()->use() does:
'generators' => [
'builder' => App\Console\Commands\BuilderCommand::class,
],Swapping Generators says which class to extend.
bases
The class a file type's generated classes extend, by file type id:
'bases' => [
'dto' => App\Support\BaseData::class,
'view-model' => null,
'value-object' => null,
'action' => null,
],null lets mod decide: a supported package when it is installed, else a base class mod writes into your app on first use. A configured base wins over an installed package, and mod:bases writes nothing for it. Stubs lists each file type's options.
bases_path
The folder generated base classes go in, relative to the app. Its namespace comes from the layout's roots, so the default writes App\Support\Data\DataTransferObject and App\Support\ViewModels\ViewModel:
'bases_path' => 'app/UI',
// -> App\UI\ViewModels\ViewModel in app/UI/ViewModels/ViewModel.phpA folder outside app/ and every root of the layout has no namespace, so generating a class that needs a base exits with an error saying so.
The folders bases go in are left out of placement and discovery, so a base is never taken for a module or for one of a file type's classes. The ddd layout keeps its bases in src/Domain/Shared whatever this is set to.
discovery
enabled set to false turns all of discovery off: providers, commands, listeners, subscribers, migration folders, factories and policies.
Discovery.file_types
Maps a file type id to the type it is discovered as: provider, command, listener, subscriber, directory, or false to stop discovering it. Merged over the defaults:
'discovery' => [
'file_types' => [
'handler' => 'listener',
'migration' => false,
],
],By default, the provider, command, listener and subscriber file types are discovered as themselves, and timestamped file types such as migration as directories. Keys are file type ids, and each must be a file type of the active layout: an unknown key stops the app with an error listing the layout's file types. handler above is a file type the app declares with generates(). File types that hold classes map to a class type, and file types that hold plain files, such as migrations, only to directory.
Discovery.cache
The cache file mod:cache writes, relative to the app.
Discovery.on_stale_cache
| Value | When the layout or discovery settings changed after the cache was written |
|---|---|
'scan' | Ignores the cache, scans instead without rewriting it, and logs a warning |
'fail' | Stops the app booting until the cache is rebuilt with mod:cache or removed |
Discovery.factories and Discovery.policies
true lets Model::factory() and Gate::getPolicyFor() find a model's factory and policy through the layout, with no newFactory() method or Gate::policy() call needed. false turns each off. mod:model -f still writes newFactory(), so the model keeps working without mod.
routes.order
'routes' => [
'order' => ['Billing', 'Knowledge'],
],Mod::routes() loads these modules first, followed by the rest alphabetically. Unknown names produce a warning. only and except filter each loading call; see Module Routes.