This is the full developer documentation for Laravel Modules # Laravel Modules > One app. Many self-contained modules. Self-contained modules Each module holds its own providers, routes, controllers, models, views, migrations, config and translations in one folder. Generators `module:make` creates a module. `module:make-controller`, `module:make-model`, `module:make-migration` and more create the classes inside it. Enable and disable Disable a module and the package stops registering its providers. Its routes disappear until you enable it again. Module-aware database commands `module:migrate`, `module:seed` and the rollback, reset, refresh and fresh variants run for one module or for all of them. Install the package with Composer: ```bash composer require nwidart/laravel-modules ``` [Introduction](/laravel-modules/start-here/introduction/)What the package is and when modules help. [Your first module](/laravel-modules/start-here/first-module/)Build a Blog module step by step. [Guides](/laravel-modules/guides/modules/create-a-module/)Task-based steps, starting with creating a module. [Concepts](/laravel-modules/concepts/how-modules-boot/)How modules boot, and why the package works this way. [Artisan commands](/laravel-modules/reference/commands/)Every command, argument and option. [Upgrading](/laravel-modules/upgrading/compatibility/)Which version fits which Laravel, and how to move to 13. # Autoloading and the Composer merge plugin > Why Laravel Modules uses wikimedia/composer-merge-plugin, what it merges, and how it compares to manual PSR-4 entries. Module classes load through Composer. This page explains how and why the package uses a Composer plugin. For setup steps, see [Installation](/laravel-modules/start-here/installation/). ## The problem [Section titled “The problem”](#the-problem) A module holds classes in a namespace such as `Modules\Blog\`. PHP finds those classes through Composer’s autoloader, so Composer needs to know the namespace and directory. There are three ways to configure it. ### One PSR-4 entry for all modules [Section titled “One PSR-4 entry for all modules”](#one-psr-4-entry-for-all-modules) Before version 11, the application’s `composer.json` used a single entry: ```json "autoload": { "psr-4": { "Modules\\": "Modules/" } } ``` This requires no plugin and no `composer.json` edits when adding modules. However, it forces every module namespace to mirror its folder tree from `Modules/` down. With the default `app/` layout, `Modules\Blog\Http\Controllers\X` lives in `Modules/Blog/app/Http/Controllers/X.php`, so this entry cannot find it. Modules also cannot define their own autoload rules or move out as standalone packages unchanged. ### One PSR-4 entry per module, written by hand [Section titled “One PSR-4 entry per module, written by hand”](#one-psr-4-entry-per-module-written-by-hand) You can add one entry per module in the application’s `composer.json`, such as `"Modules\\Blog\\": "Modules/Blog/app/"`. This supports the default layout without a plugin. The cost is manual maintenance. You must edit the root `composer.json` for every module, duplicating what the module already declares. Composer also ignores each module’s own `autoload` and `autoload-dev` maps (factories, seeders, tests), so you must copy those entries into the root file too. ### One entry per module, merged [Section titled “One entry per module, merged”](#one-entry-per-module-merged) Since version 11, each module declares its own `autoload` map in its `composer.json`, and the application merges them using `wikimedia/composer-merge-plugin`: ```json "extra": { "merge-plugin": { "include": [ "Modules/*/composer.json" ] } } ``` When Composer builds the autoloader, the plugin reads every matching file and merges its sections into the root config. Because this package requires the plugin, Composer installs it automatically and asks once whether to trust it in `allow-plugins`. If `allow-plugins` sets the plugin to `false`, Composer skips it and module classes do not autoload. The `composer.json` generated by `module:make` maps `Modules\Blog\` to `app/` and adds entries for factories, seeders, and tests. See [Anatomy of a module](/laravel-modules/concepts/module-anatomy/). ## What the merge does with a module `composer.json` [Section titled “What the merge does with a module composer.json”](#what-the-merge-does-with-a-module-composerjson) The plugin merges `autoload`, `autoload-dev`, `require`, and `require-dev` (`merge-dev` is enabled by default). A module can therefore declare its own package dependencies. The plugin skips `extra` and `scripts` unless you enable `merge-extra` or `merge-scripts`. See the [plugin README](https://github.com/wikimedia/composer-merge-plugin#readme) for all options. `module:update` handles what the merge plugin leaves out. It copies a module’s `scripts` into the root `composer.json`. It also runs `composer require` (or `--dev`) for module dependencies so Composer installs them right away instead of waiting for `composer update`. See [module:update](/laravel-modules/reference/commands/module-management/#moduleupdate). ## Why the autoloader must be rebuilt [Section titled “Why the autoloader must be rebuilt”](#why-the-autoloader-must-be-rebuilt) Composer writes its autoload map to `vendor/composer/` when you run it. Rebuild the root autoloader after adding a module manually, copying a module folder, or editing a module’s `composer.json`. `module:make` runs `composer dump-autoload` in the application root for you. `module:dump` does not rebuild the application autoloader. It runs `composer dump -o -n -q` inside each module folder, leaving the root map unchanged. See [module:dump](/laravel-modules/reference/commands/module-management/#moduledump). Module service providers listed in `module.json` are classes too, so they must autoload before the package can register them. ### Plain modules [Section titled “Plain modules”](#plain-modules) `module:make --plain` writes no `composer.json`. The merge plugin glob matches nothing for that module, so its classes do not autoload and it has no provider. Add a `composer.json` with an `autoload` map and list a provider in `module.json` when you need them. ## The trade-off [Section titled “The trade-off”](#the-trade-off) | | One `Modules\` entry | One entry per module, by hand | Merge plugin | | ------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------- | | Setup | One line in `composer.json` | One entry per module | A plugin and an `include` entry | | New module | No `composer.json` change | Edit `composer.json`, rebuild autoloader | Rebuild autoloader (`module:make` runs it) | | Layout | Namespace equals folder tree; breaks default `app/` layout | Free | Free; each module maps its own namespaces | | Module-level autoload (factories, seeders, tests) | Not possible | Copied by hand | Merged from the module | | Module as a package | Needs a rewrite | Module `composer.json` works, but root copy can drift | Module `composer.json` works as-is | | Extra dependency | None | None | `wikimedia/composer-merge-plugin`, trusted in `allow-plugins` | The plugin executes code during Composer commands, so some teams choose not to trust it. Use manual per-module entries if you prefer to avoid it. Composer still installs the plugin as a dependency of this package. ## Related [Section titled “Related”](#related) * [Install and update modules](/laravel-modules/guides/distribute/install-modules/) covers modules installed through Composer or `module:install`. * [Change where modules live and their namespace](/laravel-modules/guides/modules/change-the-location-and-namespace/) covers using a folder other than `Modules/`. # Generators and stubs > How module:make commands render stubs, how paths derive namespaces, and how published stubs override defaults. Every `module:make*` command writes files from templates. This page explains how generators, paths, and stubs work together. To customise templates, see [Customise the generator stubs](/laravel-modules/guides/customise/stubs/). For stub names and tokens, see [Stubs and placeholders](/laravel-modules/reference/stubs/) and [Configuration](/laravel-modules/reference/configuration/). ## From command to file [Section titled “From command to file”](#from-command-to-file) Each file generator answers two questions: where the file goes and what it contains. `Make\GeneratorCommand` handles the shared workflow: * rejects empty names, absolute paths, and `..` segments; * creates parent folders; * writes the file, or returns an error when it exists and `--force` is not passed. The destination combines the module folder with `config('modules.paths.generator.')` (for example, `controller`). The contents come from rendering a stub with a replacement map. Keeping paths in config and templates in stub files keeps every generator command small and consistent. ## Stubs and tokens [Section titled “Stubs and tokens”](#stubs-and-tokens) A stub is a `.stub` template containing uppercase tokens wrapped in dollar signs: ```php namespace $CLASS_NAMESPACE$; class $CLASS$ { } ``` The renderer replaces all tokens in one pass. A replacement value containing `$TOKEN$` stays untouched and is never substituted again, so output never depends on replacement order. Stubs can also contain conditional sections that the generator keeps or drops based on module state (such as web or API routes in the route provider). See [Stubs and placeholders](/laravel-modules/reference/stubs/#placeholder-syntax) for both syntaxes. For `module:make`, each stub’s tokens come from `modules.stubs.replacements`. Entries can name built-in tokens or map to a class that computes dynamic values. See [Add your own stub placeholders](/laravel-modules/guides/customise/replacement-tokens/). ## Paths and namespaces [Section titled “Paths and namespaces”](#paths-and-namespaces) The path and namespace of a generated class come from one config entry, `modules.paths.generator.`: ```php 'controller' => ['path' => 'app/Http/Controllers', 'generate' => true], ``` `Support\Config\GenerateConfigReader` derives the namespace from `path` rather than storing it twice. It strips `paths.app_folder` (`app/Http/Controllers` becomes `Http/Controllers`), converts each segment to StudlyCase, and prepends the module namespace. For `Blog`, that produces `Modules\Blog\Http\Controllers`. Set `namespace` on an entry to override the derived value. Deriving the namespace from the path keeps PSR-4 autoloading in sync. If the two were separate settings, they could drift and generated classes would fail to load. `module:make` enforces this rule before writing any files. It checks that every class generator path sits inside `paths.app_folder`, or matches its StudlyCase namespace when `app_folder` is empty. See [Anatomy of a module](/laravel-modules/concepts/module-anatomy/). ### Why paths are configurable [Section titled “Why paths are configurable”](#why-paths-are-configurable) Different teams prefer different folder layouts, such as `app/Services`, `src/Domain`, or `Application/Actions`. Configurable generator paths let you pick a layout while keeping derived namespaces in step. See [Change the folder layout of modules](/laravel-modules/guides/modules/change-the-folder-layout/). ## What `generate` does [Section titled “What generate does”](#what-generate-does) Each generator entry has a `generate` flag that applies only to `module:make`. It chooses which folders and starter files a new module gets. Running `module:make-controller` or other generators later still creates folders on demand. Four generator keys (`assets`, `routes`, `views`, and `config`) also own stub files in `stubs.files`. For example, setting `paths.generator.assets.generate` to `false` skips `resources/assets`, `vite.config.js`, and `package.json`. Stubs not owned by a key (such as `composer`) ignore these flags and are skipped only if removed from `stubs.files` or when passing `--plain`. When `generate` is `true`, `module:make` also generates the main service provider, route provider, event provider, master seeder, and controller. Passing `--plain` skips all stub files and starter classes and removes the main provider from `module.json`. Flags like `--api` and `--inertia` swap the controller and views generated. ## How published stubs take over [Section titled “How published stubs take over”](#how-published-stubs-take-over) Default stubs ship in `src/Commands/stubs/`. Published copies take effect only when `stubs.enabled` is `true` and `stubs.path` points to your custom folder. See [Customise the generator stubs](/laravel-modules/guides/customise/stubs/). Keeping `stubs.enabled` separate lets `stubs.path` hold a default `vendor/` path without activating custom stubs. The package resolves the stub base path in a `booted()` callback so it sees config changed by other providers during registration. Stub lookup runs per file. When a stub is missing from your custom folder, the package falls back to its built-in copy. You only need to keep the stubs you modify. Published stubs do not update automatically during package upgrades. New tokens or conditional markers will not reach your copies until you merge them in. Check [Changes in 13.x](/laravel-modules/upgrading/13-x-release-notes/) after upgrading to see which stubs changed. # How modules boot > How LaravelModulesServiceProvider boots modules, where module providers run, what is cached, and what disabled modules cost. This page follows one request through the package, from `LaravelModulesServiceProvider` to a module route. It explains what the package reads, in which order, and what it caches. For module load order, see [Control the load order of modules](/laravel-modules/guides/modules/control-the-load-order/). ## The sequence [Section titled “The sequence”](#the-sequence) ```text LaravelModulesServiceProvider::register() 1. merge package config; bind repository, activator and module manifest; queue stub base path; register console, migration, translation, event-discovery and actuator-endpoint hooks registerModules() 2. scan module.json files, keep enabled modules, sort by priority 3. register class aliases 4. load providers through ProviderRepository (bootstrap/cache/modules.php): register() of each module provider merges module config, then registers $providers 5. include files Laravel boots all providers 6. LaravelModulesServiceProvider::boot(): publish paths and AboutCommand (console only), lazy @module directive, modules health indicator 7. ModuleServiceProvider::boot() of each module: commands, schedules, translations, views (lazy component namespaces), health indicators, migrations; route provider maps routes ``` ### 1. Bindings and hooks [Section titled “1. Bindings and hooks”](#1-bindings-and-hooks) Laravel discovers `LaravelModulesServiceProvider` automatically. At the start of `register()`, it merges `config/config.php` under `modules`. Doing this first lets the console provider and auto-discovery hooks read merged config. Next, it binds three singletons: * the module repository (`RepositoryInterface`, alias `modules`); * the activator (`ActivatorInterface`), chosen from `modules.activator` and `modules.activators`; * the `ModuleManifest`. These bindings are lazy, so nothing scans on disk yet. The provider also queues a `booted()` callback to set the stub base path once every provider has registered. This lets it see config set by other providers. See [Generators and stubs](/laravel-modules/concepts/generators-and-stubs/#how-published-stubs-take-over). Finally, it registers `ConsoleServiceProvider` and hooks migration and translation auto-discovery. It also enables module listener name guessing for Laravel event discovery and registers the `modules` Actuator endpoint when `nwidart/laravel-actuator` is installed. ### 2. Scan, filter and sort [Section titled “2. Scan, filter and sort”](#2-scan-filter-and-sort) `registerModules()` asks `ModuleManifest` for the data of enabled modules. The manifest: 1. Finds every `module.json` in the scan paths. By default, that is `modules.paths.modules`, plus `modules.scan.paths` when `modules.scan.enabled` is `true`. The package appends `/*` to any path that does not end with it and reads `/module.json`. The default `vendor/*/*` entry therefore finds `vendor/acme/blog/module.json`. See [Load modules from extra locations](/laravel-modules/guides/modules/scan-extra-locations/). 2. Keeps modules that the activator marks enabled. 3. Sorts them in ascending order by `priority` in `module.json` (a missing priority counts as `0`). Lower numbers register first. Equal priorities keep scan order: configured scan paths first, then alphabetical folder order within each path. The result is a priority-ordered list of provider classes, aliases, and files. A module found only by scanning has no status entry and stays disabled until you enable it. Its classes must autoload before you enable it; an enabled module with an unloadable provider stops every `artisan` command. ### 3. Aliases [Section titled “3. Aliases”](#3-aliases) Before providers load, the manifest registers each enabled module’s `aliases` with Laravel’s alias loader. When two modules declare the same alias, the one with the higher priority value (registered later) wins. ### 4. Providers and the providers manifest [Section titled “4. Providers and the providers manifest”](#4-providers-and-the-providers-manifest) The package passes the provider list to Laravel’s `ProviderRepository`, the same class that manages `bootstrap/cache/services.php`. It writes its manifest next to it at `bootstrap/cache/modules.php` and rebuilds it whenever the provider list changes. Deferred providers register only when their services are resolved; eager providers register immediately. The file is always named `modules.php` inside Laravel’s cache folder. On Laravel Vapor, where `bootstrap/cache` is read-only, `modules.vapor_maintenance_mode` moves it next to the config cache. This file caches the provider list only, not the module scan. See [What is cached](#what-is-cached). No command deletes `bootstrap/cache/modules.php`, and `php artisan optimize:clear` leaves it in place. Running `module:disable` does not delete it either. The next request detects the changed provider list and rewrites the file. `ProviderRepository` calls `register()` on each eager provider while the package provider is still registering. Each module’s `ModuleServiceProvider::register()` merges the module config first, then registers every class in `$providers` (by default, its route and event providers). Sub-providers can read the module config in their `register()`. ### 5. Files [Section titled “5. Files”](#5-files) After all enabled module providers register, the manifest includes each module’s `files` using `include_once`. Helper files listed in `files` load once per request, after module provider registration finishes. ### 6. Boot [Section titled “6. Boot”](#6-boot) Laravel calls `boot()` on all providers once registration completes. `LaravelModulesServiceProvider::boot()` runs three tasks: * **Console only:** registers publish paths (`config`, `stubs`, `vite`) and adds the package version to `php artisan about`. * **Blade directive:** registers the `@module` directive lazily via `callAfterResolving('blade.compiler')`, avoiding Blade compiler instantiation on requests that do not compile templates. * **Health indicator:** calls `HealthIndicators::register()` to register the `modules` indicator with `nwidart/laravel-actuator`. Each module’s `ModuleServiceProvider::boot()` then registers: * commands (`$commands`) and schedules (`configureSchedules()`, deferred until `Schedule` resolves); * translations (and config only if a subclass skipped `parent::register()`); * views, plus Blade component namespaces registered lazily via `callAfterResolving('blade.compiler')`; * module health indicators (`registerHealthIndicators()`); * module migrations (`loadMigrationsFrom()`). The module’s route provider extends Laravel’s `RouteServiceProvider` and maps its route files. See [Module service provider](/laravel-modules/reference/api/module-service-provider/) for each step. For the enabled/disabled filter in step 2, see [Module status and activators](/laravel-modules/concepts/status-and-activators/). ## Where module providers run among your own [Section titled “Where module providers run among your own”](#where-module-providers-run-among-your-own) The package loads module providers inside its own `register()`. Laravel registers discovered package providers before application providers in `bootstrap/providers.php`. Module providers therefore run ahead of your application providers: * **Registration:** a module’s `register()` runs before your `App\Providers` classes. When both bind the same abstract, your application binding registers later and wins. * **Boot:** a module’s `boot()` runs before your application providers’ `boot()`. * **Config merging:** a module merges its config files in `register()`, before registering `$providers`. The config is available in its sub-providers’ `register()`, in later providers’ `register()`, and in every provider’s `boot()`. Existing values under the module key — published `config/` files or values set earlier — win via `mergeApplicationConfig()`. Associative arrays merge recursively; scalars, lists, and `[]` replace module values. Values set later in `register()` or `boot()` also win. See [Config files](/laravel-modules/reference/api/module-service-provider/#config-files). * **Earlier packages:** a package Laravel discovers before this one cannot read module config in `register()`. Read it in `boot()` instead. Other packages that Laravel discovers before this one register first. Laravel controls discovery order among packages. The older `Module::boot()` and `Module::register()` methods handled this work themselves. The package no longer calls them; both are [deprecated](/laravel-modules/upgrading/deprecations/). ## What is cached [Section titled “What is cached”](#what-is-cached) The package maintains two separate caches: | Cache | Where | Lifetime | Holds | | ------------------ | -------------------------------------------- | --------------------------------------- | --------------------------------------------------------------------- | | Providers manifest | `bootstrap/cache/modules.php` | On disk until the provider list changes | Enabled module providers stored by Laravel’s `ProviderRepository`. | | Scan | Memory, in repository and manifest instances | One PHP process | Decoded `module.json` files and the `Module` objects built from them. | The package writes no other cache file and has no `module:cache` command. Writing the scan to disk saved about 2 ms at 200 modules while adding stale-cache risk. Earlier versions skipped the in-memory scan cache in tests, so each `module_path()` call re-read every `module.json`. Caching the scan in 13.3.0 cut a 200-module test from 3.3 s to 249 ms. Laravel’s route cache is separate from the package. With cached routes, a disabled module keeps its routes and a new module has none until `php artisan optimize` runs again. See [Deploy an application that uses modules](/laravel-modules/guides/production/deploy/). Both the repository and the manifest are container singletons. The manifest reuses the `module.json` data the repository already read, so each file is read once per application. Each test application starts with an empty scan. ### Why `Module::resetModules()` exists [Section titled “Why Module::resetModules() exists”](#why-moduleresetmodules-exists) The scan cache lives per repository instance for the lifetime of one PHP process. A new web request or `php artisan` invocation always starts fresh. Long-lived processes, such as queue workers or tests, keep their scan and go stale if module folders change underneath them. Call `Module::resetModules()` to clear the cache so the next call rescans disk. The package calls `resetModules()` automatically after `module:make`, `module:delete`, `module:install`, and `addLocation()`. Code that adds or removes module folders directly — such as a test copying a fixture module — must call it manually. Until then, `all()` and `count()` return the previous list. A lookup by name that misses rescans once if the configured scan paths changed. ## What a disabled module costs [Section titled “What a disabled module costs”](#what-a-disabled-module-costs) The scan reads every `module.json`, including disabled modules. A disabled module costs one file read and one activator lookup. Its providers never load, so it adds no provider registration, routes, views, or migration paths. Provider registration accounts for most module boot overhead. With 200 generated modules (`php artisan optimize`, Xdebug off, OPcache on), a web request took about 77 ms versus 32 ms with no modules. Most of that gap came from Laravel booting three providers per module. Absolute timings vary by machine, but disabling unused modules removes their providers from every request. A module provider also skips its config directory scan on web requests when config is cached. See [Deploy an application that uses modules](/laravel-modules/guides/production/deploy/). # Anatomy of a module > What a module folder contains, why module.json and composer.json are separate, and how namespaces map to app/. A module is a folder shaped like a small Laravel package. This page explains what each part holds and why. For creation steps, see [Create a module](/laravel-modules/guides/modules/create-a-module/). For every manifest field, see [module.json](/laravel-modules/reference/module-json/). ## What `module:make` generates [Section titled “What module:make generates”](#what-modulemake-generates) With default config, `php artisan module:make Blog` creates: * Modules * Blog * app * Http * Controllers/ * … * Providers/ * … * config/ * … * database * factories/ * … * migrations/ * … * seeders/ * … * resources * assets/ * … * views/ * … * routes * api.php * web.php * tests * Feature/ * … * Unit/ * … * composer.json * module.json * package.json * vite.config.js A folder is generated initially only when its `generate` flag is `true` in `modules.paths.generator`. Each stub file follows the flag of the generator key that owns it. See [Generators and stubs](/laravel-modules/concepts/generators-and-stubs/#what-generate-does). Later `module:make-*` commands create folders such as `app/Models/` on demand. A module created with `--plain` includes the folders and `module.json`, with no stub files or `composer.json`, so its classes do not autoload. See [Autoloading](/laravel-modules/concepts/autoloading/#plain-modules). ## Two manifests, two readers [Section titled “Two manifests, two readers”](#two-manifests-two-readers) A module has two JSON files because two tools read them. | File | Read by | Holds | | --------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `module.json` | This package | `name`, `description` (read by `Module::getDescription()` and `ModulesEndpoint`), `priority`, `providers`, `aliases`, and `files`. `ModulesEndpoint` also reads optional `version`. `module:make` writes `alias` and `keywords` too, which the package does not read. | | `composer.json` | Composer | `autoload` and `autoload-dev` maps, plus optional `require`, `require-dev`, and `scripts`. | `module.json` tells the package how to boot the module. `composer.json` tells PHP how to find its classes. Keeping them separate lets a module follow Composer’s standard format, so you can extract it into a standalone Composer package later without rewriting autoload rules. `module.json` is the only file in the folder owned by this package. Everything else is ordinary Laravel code, with the main provider extending `ModuleServiceProvider`. The two files overlap on provider lists. Laravel package discovery reads `extra.laravel.providers` in `composer.json` without checking module status, which would register providers even for disabled modules. This package registers providers from `module.json` after checking status, so the generated `composer.json` leaves `extra.laravel.providers` empty. See [module.json](/laravel-modules/reference/module-json/). Module status (enabled or disabled) lives in neither file. See [Module status and activators](/laravel-modules/concepts/status-and-activators/). ## The `app/` folder and the namespace [Section titled “The app/ folder and the namespace”](#the-app-folder-and-the-namespace) The module’s `composer.json` maps `Modules\Blog\` to `modules.paths.app_folder`, which defaults to `app/`. A class in `Modules/Blog/app/Http/Controllers/PostController.php` therefore has the namespace `Modules\Blog\Http\Controllers`. The `app/` segment is the namespace root and does not appear in the class name. This mirrors a standard Laravel application, where `App\` maps to `app/`. Three folders outside `app/` get their own autoload entries: | Namespace | Folder | | ---------------------------------- | ---------------------------- | | `Modules\Blog\Database\Factories\` | `database/factories/` | | `Modules\Blog\Database\Seeders\` | `database/seeders/` | | `Modules\Blog\Tests\` | `tests/` (in `autoload-dev`) | Generator paths and `app_folder` must agree so generated classes autoload. `module:make` exits with an error if a class generator path sits outside `app_folder`. See [Change the folder layout of modules](/laravel-modules/guides/modules/change-the-folder-layout/) and [Generators and stubs](/laravel-modules/concepts/generators-and-stubs/). ## Providers are the main entry point [Section titled “Providers are the main entry point”](#providers-are-the-main-entry-point) A module has no separate bootstrap file. The package reads `providers`, `aliases`, and `files` from `module.json` during boot and hands the providers to Laravel. See [How modules boot](/laravel-modules/concepts/how-modules-boot/). The main provider extends [`ModuleServiceProvider`](/laravel-modules/reference/api/module-service-provider/). It registers config, views, translations, migrations, commands (`$commands`), schedules (`configureSchedules()`), and Actuator health indicators (`$healthIndicators`). It also registers additional providers listed in `$providers` — by default, a route provider and an event provider. Because providers drive module behaviour, a module can do anything a Laravel service provider can do. The package adds no custom module lifecycle on top. If a module needs non-standard setup, change its provider rather than the package. ## A module is a convention, not a boundary [Section titled “A module is a convention, not a boundary”](#a-module-is-a-convention-not-a-boundary) A module uses the same layout as a Laravel package: `composer.json`, providers, `routes/`, `config/`, `resources/`, `database/`, and `tests/`. This makes it straightforward to move a module into its own repository later. See [Publish a module as a Composer package](/laravel-modules/guides/distribute/publish-a-module-as-a-package/). The trade-off is that modules share the container, database, config, and autoloader with the host application. See the [introduction](/laravel-modules/start-here/introduction/) for what the package does not enforce. # Module status and activators > Why module status lives outside module.json, what FileActivator stores, and what disabling a module changes. Every module is enabled or disabled. This page explains where the status lives, why, and what it changes at runtime. For commands, see [Enable and disable modules](/laravel-modules/guides/modules/enable-and-disable-modules/). ## Why the status is not in `module.json` [Section titled “Why the status is not in module.json”](#why-the-status-is-not-in-modulejson) Before version 6, each module stored its status in `module.json`. Version 6 moved status out of the manifest so it can live elsewhere, such as a database. Keeping status outside `module.json` gives two benefits: * `module.json` describes the module, while status describes a specific installation. The same module can be enabled in production and disabled locally without modifying module files. * Modules installed from packages can be enabled or disabled without editing files in `vendor/`. The package reads status through `ActivatorInterface`, making the storage replaceable. ## What the file activator stores [Section titled “What the file activator stores”](#what-the-file-activator-stores) The default activator, `FileActivator`, stores a JSON object mapping module names to booleans. It loads the file once on instantiation and rewrites it on each change. By default, it writes to `modules_statuses.json` at the application root so you can inspect and commit it. See [FileActivator](/laravel-modules/reference/api/contracts/#fileactivator) and [Configuration](/laravel-modules/reference/configuration/#activators) for format details and failure cases. With `nwidart/laravel-actuator` installed, the `modules` health indicator reports every module (enabled and disabled) with `enabled: true` or `false`. It reports `DOWN` when an enabled module is missing from disk. The package also registers the read-only `/actuator/modules` endpoint to inspect module metadata. See [Report module health with the actuator](/laravel-modules/guides/production/health-checks/) and [Expose modules through the actuator](/laravel-modules/guides/production/actuator-modules-endpoint/). A missing or empty file means no statuses. Invalid JSON or a non-empty JSON list throws `InvalidJsonException`. The activator refuses to treat a corrupt file as empty so a later write cannot wipe existing statuses. ### A missing entry means disabled [Section titled “A missing entry means disabled”](#a-missing-entry-means-disabled) `hasStatus()` returns `false` for “enabled” when a module has no entry. Any scanned module absent from the statuses file is disabled. This default is safe. A folder added under `Modules/` or an extra scan location (such as `vendor/` or `plugins/`) stays inactive until you enable it. Its classes must autoload before you enable it. See [Load modules from extra locations](/laravel-modules/guides/modules/scan-extra-locations/). `module:make` writes the status entry as enabled unless you pass `--disabled`. `module:delete` removes the status entry along with the folder. ### Commit the file, or keep it per environment [Section titled “Commit the file, or keep it per environment”](#commit-the-file-or-keep-it-per-environment) Commit `modules_statuses.json` when every environment should run the same modules. Keep it per environment when deployments differ. | | File committed | File kept per environment | | ------------------------ | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | What you get | Enabled modules are reviewed and deployed with code. Fresh clones match production. | Each environment chooses its own modules, such as disabling a module locally. | | What a deploy does | Nothing extra: the file arrives with the code. | The file must exist on the server before the first request. | | When the file is missing | Not applicable. | Every module is disabled. The app boots without module routes, views, or config, with no error. | | Cost | A local `module:disable` appears in `git status`. Branches enabling different modules can conflict on this file. | Nothing in the repository records which modules production runs. | Either way, a missing file leaves every module disabled. See [Enable and disable modules](/laravel-modules/guides/modules/enable-and-disable-modules/) for commands and [Deploy an application that uses modules](/laravel-modules/guides/production/deploy/) for deploy practices. That guide recommends committing the file. ## What a status changes [Section titled “What a status changes”](#what-a-status-changes) The package reads module status during registration. See [How modules boot](/laravel-modules/concepts/how-modules-boot/). | Part of the module | Enabled | Disabled | | ---------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------- | | Providers in `module.json` | Registered | Not registered | | Routes, views, config, translations, schedules | Registered by providers | Absent, because providers do not load | | Commands in provider `$commands` | Registered | Not registered | | Health indicators in `$healthIndicators` | Registered with `nwidart/laravel-actuator` | Not registered | | Migrations | Added to `php artisan migrate` by provider and `auto-discover.migrations` | Not added | | `aliases` and `files` of `module.json` | Registered and included | Skipped | | Root Vite builds (`vite-module-loader.js`) | Entry points included | Skipped | With cached routes, status changes do not affect routing until `php artisan optimize` runs again. Disabled modules keep cached routes, and newly enabled ones have none. Commands that take a module name act on disabled modules too: `module:migrate Blog` finds `Blog` by name. With `--all`, commands that declare `--direction`, plus `module:migrate-refresh` and `module:prune`, run on enabled modules only. Other `--all` commands run on every module, enabled or disabled. See [Database commands](/laravel-modules/reference/commands/database/) and [Module management commands](/laravel-modules/reference/commands/module-management/). ### What a status does not change [Section titled “What a status does not change”](#what-a-status-does-not-change) Status does not affect Composer autoloading. Classes in a disabled module still load when referenced, because Composer merges each module’s `composer.json` regardless of status. See [Autoloading and the Composer merge plugin](/laravel-modules/concepts/autoloading/). Disabling a module does not block imports of its classes. Code in another module can still instantiate a class from a disabled module until it relies on provider setup, such as a view namespace or config key. Event discovery works the same way. By default, Laravel discovers listeners only in `app/Listeners`, while a generated module `EventServiceProvider` registers only its `$listen` array. See [Use events and listeners in a module](/laravel-modules/guides/console-and-events/events-and-listeners/). When you opt in to discovery, Laravel scans the directories you list in `withEvents(discover: [...])`. The package only maps discovered files under `Modules/` to module class names; it adds no discovery paths itself. A glob like `Modules/*/app/Listeners` matches disabled modules too, so their listeners still run if their classes autoload. Treat module status as “is this module wired into the application”, not as an access control boundary. ## What a disabled module costs [Section titled “What a disabled module costs”](#what-a-disabled-module-costs) A disabled module costs one `module.json` read and one lookup in the statuses file. See [How modules boot](/laravel-modules/concepts/how-modules-boot/#what-a-disabled-module-costs). ## When a custom activator makes sense [Section titled “When a custom activator makes sense”](#when-a-custom-activator-makes-sense) The file activator fits most applications. Write a custom activator when: * status must differ per environment, tenant, or customer; * multiple application servers must share one status store; * status must change from an admin interface with an audit trail. A custom activator implements `Contracts\ActivatorInterface` and is registered under `modules.activators` with a `class` key. `modules.activator` selects the active entry. The package throws `InvalidActivatorClass` if the name is unknown, the `class` key is missing, or the class does not exist. Status is read at boot on every request. A database-backed activator adds a query to every request and requires the database to be reachable during boot. See [Store module status with a custom activator](/laravel-modules/guides/customise/custom-activator/). # Use the package with AI coding assistants > The Laravel Boost guideline and skill that laravel-modules ships, how to turn them on, and the llms.txt files of this site. The package ships a guideline and a skill for [Laravel Boost](https://github.com/laravel/boost). Boost discovers package guidelines and skills automatically, and you opt in to install them. This site also publishes plain-text `llms.txt` files for language models. ## What the package ships [Section titled “What the package ships”](#what-the-package-ships) Two Blade templates ship under `resources/boost/` (installed at `vendor/nwidart/laravel-modules/resources/boost/`): | File | Kind | Content | | -------------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `resources/boost/guidelines/core.blade.php` | Guideline | Seven bullets: modular layout, `module:make`, `Modules\ModuleName` namespaces, keeping logic out of `app/`, Actuator `$healthIndicators` (`module:make-health-indicator`), and the `modules` actuator endpoint (`GET /actuator/modules`). | | `resources/boost/skills/laravel-modules-development/SKILL.blade.php` | Skill (`laravel-modules-development`) | Commands and conventions for modules, generators (`module:make-config`, `module:make-job-middleware`, `--attributes`, `--json-api`), event discovery, health indicators, `GET /actuator/modules`, migrations, and Inertia v3. | The skill activates for tasks mentioning `module:make`, module commands, or a `Modules/` directory. It renders commands through `$assist->artisanCommand()`. In Laravel Boost, guidelines load at session start while skills load on demand. ## Turn the guideline and skill on [Section titled “Turn the guideline and skill on”](#turn-the-guideline-and-skill-on) Boost reads `resources/boost/guidelines/` and `resources/boost/skills/` from installed Composer packages. In Laravel Boost 2.10.4, it lists `nwidart/laravel-modules (guidelines, skills)` and waits for you to opt in. Install Boost and select the package when prompted: ```bash composer require laravel/boost --dev php artisan boost:install ``` Pick `nwidart/laravel-modules` in the prompt (`boost:update` offers the same prompt later). To configure it without a prompt, add the package to `boost.json` in your project root: boost.json ```json { "packages": ["nwidart/laravel-modules"] } ``` Run `php artisan boost:update`, then verify that your assistant lists `laravel-modules-development`. See the [Laravel Boost documentation](https://laravel.com/docs/13.x/boost) for Boost commands. ## Site files for language models [Section titled “Site files for language models”](#site-files-for-language-models) This site publishes plain-text versions of the documentation at the site root: | File | URL | | ---------------- | ---------------------------------------------------------- | | `llms.txt` | | | `llms-full.txt` | | | `llms-small.txt` | | Point your assistant at one of these files when it needs full documentation context. `llms-small.txt` is the compact version. The site build generates all three from these pages. When an assistant disagrees with [Artisan commands](/laravel-modules/reference/commands/) or [Configuration](/laravel-modules/reference/configuration/), trust those reference pages: they are verified against the source code. # Community packages > Companion and third-party packages that extend laravel-modules, and what each adds beyond the core package. This page lists active packages that extend or integrate with `nwidart/laravel-modules`. ## Suggested companion package [Section titled “Suggested companion package”](#suggested-companion-package) `composer.json` lists this optional companion package under `suggest`: | Package | What it does | Integration with the core | | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [`nwidart/laravel-actuator`](https://github.com/nWidart/laravel-actuator) (`^1.1`) | Adds Spring Boot Actuator-style operational endpoints and health checks to Laravel. | When installed, Laravel Modules registers the `modules` health indicator, per-module `$healthIndicators`, and the read-only `/actuator/modules` endpoint. See [Report module health with the actuator](/laravel-modules/guides/production/health-checks/) and [Expose modules through the actuator](/laravel-modules/guides/production/actuator-modules-endpoint/). | ## Third-party packages [Section titled “Third-party packages”](#third-party-packages) Their authors maintain these packages. This project does not maintain, test, or support them. Check each repository for supported Laravel Modules versions. The “Differs from the core” column reflects each package’s README. | Package | What it does | Differs from the core | | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [`mhmiton/laravel-modules-livewire`](https://github.com/mhmiton/laravel-modules-livewire) | Registers Livewire components in modules and adds `module:make-livewire` (single-file and multi-file). | Core has no Livewire integration. This package adds a Livewire generator and registers components under module namespaces, such as ``. | | [`dcblogdev/laravel-module-generator`](https://github.com/dcblogdev/laravel-module-generator) | Builds modules from custom folder templates with `module:build`. | `module:make` renders the fixed stubs in `modules.stubs.files`. `module:build` copies a chosen template folder (shipping Breeze CRUD templates for web and API) and replaces placeholders in names and contents. Run `module:enable` and `composer dump-autoload` after generating. | To add a package to this list, see [Contribute and get help](/laravel-modules/ecosystem/contributing-and-support/). # Contribute and get help > Where to ask questions, report bugs and security problems, contribute code or documentation, and sponsor the project. ## Get help [Section titled “Get help”](#get-help) * Ask a question in [GitHub Discussions](https://github.com/nWidart/laravel-modules/discussions). * Report a bug in [GitHub Issues](https://github.com/nWidart/laravel-modules/issues). Include the package version, the Laravel version, the command you ran and the output. ## Report a security problem [Section titled “Report a security problem”](#report-a-security-problem) Use the [private report form](https://github.com/nWidart/laravel-modules/security/advisories/new). You can also open it from the repository’s Security tab with “Report a vulnerability”. Do not post the details in a public issue, discussion or pull request. The full policy is in [SECURITY.md](https://github.com/nWidart/laravel-modules/blob/master/SECURITY.md). A security fix lands on `master` and, when the problem exists in version 12, on `12.x`. See [Version compatibility](/laravel-modules/upgrading/compatibility/). ## Contribute code [Section titled “Contribute code”](#contribute-code) Read [CONTRIBUTING.md](https://github.com/nWidart/laravel-modules/blob/master/CONTRIBUTING.md) first. In short: 1. Fork the repository and branch from `master`. Changes target `master`. `12.x` accepts security fixes only. 2. Run `composer check` before you open a pull request. It runs the style check, static analysis and the tests. 3. Write commit messages as [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), for example `fix(migrations): honour --pretend on module:migrate-rollback`. CI checks every commit, and the changelog and version number come from them. ## Contribute to this documentation [Section titled “Contribute to this documentation”](#contribute-to-this-documentation) To add a package to the [community packages](/laravel-modules/ecosystem/community-packages/) list, open a pull request that changes that page. Each page has an edit link at the bottom that opens the Markdown file on GitHub. To run the site locally, see [docs/README.md](https://github.com/nWidart/laravel-modules/blob/master/docs/README.md). Update the matching documentation page in the same pull request whenever you change user-facing behaviour. ## Sponsor the project [Section titled “Sponsor the project”](#sponsor-the-project) The repository lists two sponsor accounts in [`.github/FUNDING.yml`](https://github.com/nWidart/laravel-modules/blob/master/.github/FUNDING.yml): [nwidart](https://github.com/sponsors/nwidart) and [dcblogdev](https://github.com/sponsors/dcblogdev). # Add Artisan commands to a module > Generate an Artisan command in a module with module:make-command, register it in the module provider and list it. To add the `blog:prune-old` Artisan command to the `Blog` module, generate the class and register it in the module’s service provider. You need an enabled `Blog` module. Laravel auto-discovers commands only in `app/Console/Commands`, so module commands require explicit registration. 1. Generate the command with `--command` to set its signature. ```bash php artisan module:make-command PruneOldPosts Blog --command=blog:prune-old ``` This creates `Modules/Blog/app/Console/PruneOldPosts.php` (`Modules\Blog\Console\PruneOldPosts`). 2. Implement `handle()`. Modules/Blog/app/Console/PruneOldPosts.php ```php info('Old posts pruned.'); } } ``` 3. Register the class in the `$commands` property of the module service provider (uncomment the property in the generated provider). Modules/Blog/app/Providers/BlogServiceProvider.php ```php /** * Command classes to register. * * @var string[] */ protected array $commands = [ \Modules\Blog\Console\PruneOldPosts::class, ]; ``` 4. Check the result by listing the module’s commands and running the new command. ```bash php artisan module:list-commands Blog ``` The output lists `blog:prune-old` under `Blog/Console`. ```bash php artisan blog:prune-old ``` ```text Old posts pruned. ``` ## Related [Section titled “Related”](#related) * [`module:make-command`](/laravel-modules/reference/commands/generators/#modulemake-command) and [`module:list-commands`](/laravel-modules/reference/commands/module-management/#modulelist-commands) * [Module service provider: properties](/laravel-modules/reference/api/module-service-provider/#properties) * [Add your own module commands and generators](/laravel-modules/guides/customise/custom-commands/) * [Schedule tasks from a module](/laravel-modules/guides/console-and-events/schedules/) # Use events and listeners in a module > Generate an event and a listener in a module, map them in the module EventServiceProvider and check the mapping with event:list. To run a listener when the `Blog` module publishes a post, generate the event and listener and map them in the module’s `EventServiceProvider`. You need an enabled `Blog` module; `module:make` creates `Modules/Blog/app/Providers/EventServiceProvider.php` and registers it in the main provider. 1. Generate the event. ```bash php artisan module:make-event PostPublished Blog ``` This creates `Modules/Blog/app/Events/PostPublished.php` (`Modules\Blog\Events\PostPublished`). 2. Generate the listener. `--event` types the `handle()` parameter, and `--queued` makes it implement `ShouldQueue`. ```bash php artisan module:make-listener NotifySubscribers Blog --event=PostPublished --queued ``` This creates `Modules/Blog/app/Listeners/NotifySubscribers.php` with `handle(PostPublished $event)`. A short name like `PostPublished` resolves in the module’s `Events` namespace. Names starting with `\`, the application namespace (`App\`), `Illuminate\`, or the configured `modules.namespace` (`Modules\`) are used as fully qualified class names without needing a leading `\`. 3. Map the event to the listener in `$listen`. Modules/Blog/app/Providers/EventServiceProvider.php ```php protected $listen = [ \Modules\Blog\Events\PostPublished::class => [ \Modules\Blog\Listeners\NotifySubscribers::class, ], ]; ``` 4. Dispatch the event when a post is published. ```php use Modules\Blog\Events\PostPublished; PostPublished::dispatch(); ``` Queued listeners require a running worker (`php artisan queue:work`) unless `QUEUE_CONNECTION=sync`. 5. Check the result. ```bash php artisan event:list --event=PostPublished ``` ```text Modules\Blog\Events\PostPublished .......................................... ⇂ Modules\Blog\Listeners\NotifySubscribers (ShouldQueue) ``` ## Event discovery and modules [Section titled “Event discovery and modules”](#event-discovery-and-modules) The generated `EventServiceProvider` registers only its `$listen` array and does not scan for listeners. By default, Laravel scans only `app/Listeners`. Remove any legacy `$shouldDiscoverEvents` property from older module providers, as it has no effect. To discover module listeners automatically, add module listener folders to `withEvents()` in `bootstrap/app.php`: bootstrap/app.php ```php ->withEvents(discover: [ __DIR__.'/../app/Listeners', __DIR__.'/../Modules/*/app/Listeners', ]) ``` Keep these rules in mind when using event discovery: * `withEvents(discover: [...])` replaces Laravel’s default path, so include `app/Listeners` alongside your module glob. * The package resolves module listener file paths to their module class names automatically. * Globs match disabled modules as well (see [Module status and activators](/laravel-modules/concepts/status-and-activators/)). * Do not list a discovered listener in `$listen`, or it runs twice. * Re-run `php artisan event:cache` after changing mappings. See [Changes in 13.x](/laravel-modules/upgrading/13-x-release-notes/#behaviour-changes). ## Register a listener without `EventServiceProvider` [Section titled “Register a listener without EventServiceProvider”](#register-a-listener-without-eventserviceprovider) You can also register a listener in the module service provider’s `boot()` method. Always call `parent::boot()`: Modules/Blog/app/Providers/BlogServiceProvider.php ```php use Illuminate\Support\Facades\Event; use Modules\Blog\Events\PostPublished; use Modules\Blog\Listeners\NotifySubscribers; public function boot(): void { parent::boot(); Event::listen(PostPublished::class, NotifySubscribers::class); } ``` ## Related [Section titled “Related”](#related) * [`module:make-event`](/laravel-modules/reference/commands/generators/#modulemake-event), [`module:make-listener`](/laravel-modules/reference/commands/generators/#modulemake-listener) and [`module:make-event-provider`](/laravel-modules/reference/commands/generators/#modulemake-event-provider) * [React to module lifecycle events](/laravel-modules/guides/console-and-events/lifecycle-events/) * [Add Artisan commands to a module](/laravel-modules/guides/console-and-events/commands/) # React to module lifecycle events > Listen from the application to modules.blog.enabled, modules.*.disabled and the other lifecycle events a module fires. To run code when the `Blog` module is enabled or disabled, listen to its lifecycle events in your application. You need an enabled `Blog` module. Modules fire string events named `modules.{lowercase name}.{event}` with the `Nwidart\Modules\Module` instance as the payload. Register listeners in your application, not inside the module. When `enabled` fires, the process booted before the module was enabled, so module listeners are not registered yet. 1. Register a listener in the `boot()` method of an application service provider. app/Providers/AppServiceProvider.php ```php getName()} enabled."); }); } } ``` 2. Use a wildcard to listen across all modules. Wildcard listeners receive the event name and an array containing the payload. app/Providers/AppServiceProvider.php ```php Event::listen('modules.*.disabled', function (string $event, array $payload) { [$module] = $payload; Log::info("Module {$module->getName()} disabled."); }); ``` 3. Check the result. Disable and enable the module, then inspect the log. ```bash php artisan module:disable Blog php artisan module:enable Blog tail -n 2 storage/logs/laravel.log ``` ```text [