isn't the config read into memory during Bootstrap?
Do you need to change the config values in memory?
i'm using mcamara localization package https://github.com/mcamara/laravel-localization in app an with default language set to english as per default laravel installation config/app.php
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'en',
i need to give the user ability to change the default language dynamically using a from, ...
when i don this
$locale = 'es'; // passed from the form
Session::put('locale', $locale);
app()->setLocale(Session::get('locale'));
after submitting the form i can see the locale is changing but mcamara is not picking up the changes, It still seed the default locale = 'en'; as shown above,
not sure if there is another way to do this but i think if i can change the locale in the config/app.php file dynamically and (i mean access the file and change the locale value in php) will do the job.
Is that possible ???? is there is any better way to do this??
Any ideas ?
No, it won't change it permanently in config.php. Nothing will do that unless you write something to manually do alter the file and resave it, which I wouldn't suggest.
I told/showed you how to change it dynamically. It will only work for the current request only, which is why you use it in middleware and setting this value dynamically on every request. Every user could have their own locale if they wanted to, or whatever you're doing. Middleware executes before it hits your app code (controllers, etc)...so the config will be dynamically set on each and every request.
Then, when laravel retrieves the locale from config (which is in-memory), it will retrieve the new value instead of the one hardcoded in your /config/app.php file, because it overwrote that value in memory.
Please or to participate in this conversation.