Skip to content

Conversation

solomon-ochepa
Copy link
Contributor

Summary:

This PR introduces a core enhancement to the registerConfig() logic. It ensures that configuration files within a module (e.g., modules/Blog/config/config.php or modules/Blog/config/blog.php) override Laravel's root application configs (e.g., config/blog.php) during registration.

Why This is Necessary:

The modular architecture encourages encapsulation of logic and behavior per domain (module). However, Laravel’s default mergeConfigFrom() merges shallowly and always prioritizes existing config values, meaning module-defined values are ignored if a root config already exists.

This directly contradicts the core idea of modularity - that a module should define and control its behavior without being limited by app-level configs.

By allowing module configs to override root configs, developers get:

  • Predictable behavior across all modules.
  • Clean overrides and centralization of domain logic.
  • Better separation of concerns between global app config and module logic.

Before:

// config/blog.php
return [
    'comments' => false,
];

// Modules/Blog/config/blog.php
return [
    'comments' => true,
];

// config('blog.comments') === false

After:

// config('blog.comments') === true

Module config values now correctly override root config values.

@dcblogdev dcblogdev merged commit 71ac71c into nWidart:master Apr 28, 2025
4 of 10 checks passed
@rsd
Copy link

rsd commented Sep 22, 2025

Why is this necessary?

I am working on a deep merge of configuration keeping the top-level/root config values.

I believe this should work on the other way around.
A module's config should have default values. These default values can be final if the top-level config does not exists (no clash).
However, if after installing a module, you do not agree that these config values in the module are the correct one for you app, you replace them at the application top-level, without the need to edit the module's config file.

I am clearly missing some (maybe obvious) point.
Could you please elaborate it to me?

BTW, my plan is to have the other way around behavior as an alternative and not as a replacement of the current take.

thanks,
-rsd

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Sep 22, 2025 via email

@rsd
Copy link

rsd commented Sep 22, 2025

got it.
I might be using it wrong. Breaking a large app into smaller ones, so modules are reusable pieces.
However, the config does not fit all cases.
I am submit the PR to extend in this format too, in case it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants