Mod is pre-1.0. Minor releases may change the API until 1.0.
Skip to content

Configuration ​

Every key in config/mod.php. Publish the file with:

bash
php artisan vendor:publish --tag=mod-config
# -> config/mod.php
KeyDefaultDescription
layout'laravel'The active layout
routes.order[]Modules loaded before the alphabetical remainder
commandstrueRegister the mod:* commands
generators[]Replace the command behind a file type
basesnull for eachThe class DTOs, view models, value objects and actions extend
bases_path'app/Support'Where generated base classes go
discovery.enabledtrueTurn 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.factoriestrueFind factories for models the layout places
discovery.policiestrueFind 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().

config/mod.php
php
'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:

config/mod.php
php
'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:

config/mod.php
php
'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:

config/mod.php
php
'bases_path' => 'app/UI',
// -> App\UI\ViewModels\ViewModel in app/UI/ViewModels/ViewModel.php

A 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:

config/mod.php
php
'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 ​

ValueWhen 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 ​

config/mod.php
php
'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.

Released under the MIT License. Created by Jasper Tey.