Skip to content

Installation

To use Laravel Modules, install the package with Composer and register module autoloading in your application’s composer.json.

  • PHP 8.3 or later, with the dom, json, and simplexml extensions.
  • Laravel 13 for version 13.x. See Version compatibility for other Laravel releases, Composer constraints, PHP versions, and support.
  1. Require the package.

    Terminal window
    composer require nwidart/laravel-modules

    The package requires wikimedia/composer-merge-plugin. Composer asks whether to trust it:

    Do you trust "wikimedia/composer-merge-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]

    Answer y. Composer adds this to composer.json:

    "config": {
    "allow-plugins": {
    "wikimedia/composer-merge-plugin": true
    }
    }

    If you answered n, change the value from false to true. If you answered d or Composer did not prompt, add the entry yourself. Composer skips module autoloading until you allow the plugin.

    Laravel discovers the service provider and the Module alias automatically.

  2. Tell the plugin where the modules live. Add the merge-plugin entry to the extra section of composer.json (marked lines):

    "extra": {
    "laravel": {
    "dont-discover": []
    },
    "merge-plugin": {
    "include": [
    "Modules/*/composer.json"
    ]
    }
    },

    Match the glob to the folder in paths.modules (Configuration). The plugin merges each module’s composer.json into the application’s autoload configuration. See Autoloading and the Composer merge plugin for details.

  3. Regenerate the autoloader.

    Terminal window
    composer dump-autoload
  4. Optional: publish the configuration file to config/modules.php.

    Terminal window
    php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider" --tag=config

    The package works without publishing it. See Configuration for every key.

  5. Check the install.

    Terminal window
    php artisan module:list

    With no modules yet, the command prints only the header line:

    Status / Name ........................................ Path / priority

If you used the "Modules\\": "Modules/" autoload entry from an older version, remove it from composer.json.

To build your first module, continue with Your first module.