Skip to content

Give a module its own configuration

To give the Blog module its own settings, edit Modules/Blog/config/config.php or generate extra config files and read them with config(). You need an enabled Blog module. A new module already has Modules/Blog/config/config.php containing 'name' => 'Blog'.

ModuleServiceProvider registers every PHP file in the module’s config/ folder:

File Config key prefix
config/config.php blog
config/settings.php blog.settings
  1. Add a setting to Modules/Blog/config/config.php.

    Modules/Blog/config/config.php
    <?php
    return [
    'name' => 'Blog',
    'posts_per_page' => 15,
    ];
  2. Optional: create a second config file to group related settings.

    Terminal window
    php artisan module:make-config settings Blog

    This creates Modules/Blog/config/settings.php. Add a setting:

    Modules/Blog/config/settings.php
    <?php
    return [
    'per_page' => 10,
    ];
  3. Check the result.

    Terminal window
    php artisan config:show blog
    blog .......................................................................
    name .................................................................. Blog
    posts_per_page .......................................................... 15
    settings ⇁ per_page ..................................................... 10

    Read the values with config('blog.posts_per_page') and config('blog.settings.per_page').

Publish a module’s config files to override values from your application.

  1. Publish the config files.

    Terminal window
    php artisan module:publish-config Blog

    This creates config/blog.php and config/blog/settings.php. Add --force to overwrite existing files.

  2. Override a value in the published file.

    config/blog.php
    <?php
    return [
    'posts_per_page' => 99,
    ];
  3. Verify the merged value.

    Terminal window
    php artisan tinker --execute="echo config('blog.posts_per_page');"

    The output is 99.

Published values override module defaults:

  • Associative arrays merge recursively key by key.
  • Scalars, lists, and empty arrays ([]) replace the module’s value as a whole.
  • Unset keys keep their module defaults, and extra application keys stay intact.

If configuration is cached, run php artisan config:cache after editing a published file. See Config files for the exact merge order.