My project is two Laravel applications in one folder. Why two separate applications instead of one? I have good reasons. Anyway, for example, every time I want to change the app name in the config (config/app.php
) I go and edit the .env
file in both directories (of the two applications) and then execute artisan config:cache
to update the cached config.
It's not much of a task or anything, but it's a bad design I believe. So, I am looking for a way to take the values shared between these two application out to a separate file. And have these application load this file and override/apply the values inside it to the app configuration.
So, now I have a config.php
in the root directory (which holds the other two apps in /app1 and /app2). And inside each app's AppServiceProvider
I call the config.php
and loop through the values and set each using Config::set(..., ...)
.
This worked for me well, but of course changing the values loaded in the \Config package doesn't change the values that were fetched from it earlier to this point. For example app()->environment()
returns the value set in the config/app.php
, not the new value introduced in the global config.php
. That's because the App
library asked for the env
property before I could override it!
So, what I want your help with is: you either tell me about a more smart/standard way to achieve 1 config for 2 apps setup. Or tell me where to put the code that overrides the app config with the new values from my global config.php
(currently I put the code in register()
in App\Providers\AppServiceProvider
)
via Dewan159