I've my home route
Route::get('/', 'HomeController@index')->name('home');
And a specific route to change language
Route::get('/setLocale/{locale}', 'HomeController@setLocale')->name('setLocale');
In HomeController->setLocale($locale)
I check if $locale
is a valid locale, then simply do
\App::setLocale($locale);
Then redirect to home.
Here, in HomeController->index()
I verify locale using
$locale = \App::getLocale();
The problem is that after user CHANGES the locale, the app set the new locale, redirect, but the locale detected is still the DEFAULT locale, not the new one setup by the user.
How / where / when can I make persistent the change to app locale?
I thinked Laravel was setting a locale cookies or something when using setLocale
and re-reading it when using getLocale
but now I think it's not this the way Laravel works.
I ask, again: how can I set app locale so that is preserved after page change?