-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add ConfigMergerTrait so app config overrides module defaults #2116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… ConfigMergerTrait
When working with modular architectures like nWidart/laravel-modules, modules should always override the root app configuration because of the principle of contextual precedence. In a modular system, the app provides the global foundation — default configurations, shared behaviors, and system-wide fallbacks. Each module, however, represents a self-contained and context-specific feature set. By design, a module should encapsulate and control its own logic, dependencies, and configurations without being constrained by the global layer. Here’s why modules should “win” in case of conflicts:
In short:
|
I understand your point. However, these sane defaults are not for every situation, so you might want to change that. So you publish the configs as usual: php artisan vendor:publish --provider="Modules\Foo\FooServiceProvider" --tag="config" After this, it is natural that the config published would have precedence over the one in the module, right? Note that I am not proposing to change the default behavior. I am just giving an opportunity for the module author that wish this, to have the opportunity to edit its Service Provider. |
Why
Reusable modules need defaults while letting each app override. Today, when keys collide, module config wins.
Opt-in only; existing behavior unchanged unless providers call the new helper.
What
Nwidart\Modules\Traits\ConfigMergerTrait
mergeConfigDefaultsFrom($path, $key, $existingPrecedence = true, $deep = true)
Usage (in a module ServiceProvider)