I have some trouble updating a value in a current session ...
On first request "my-website.com/en/whatever" the language gets detected via url segment "en"
session(['locale' => $this->current->locale]);
This will be persisted into my session. It puts the value correctly in my session, but when i switch to another language - say 'de' - the locale value will not be updated again - EVER - even if I Session::save() afterwards ...
Hope someone can help me with that ...
(The language detection works absolutely fine - I dumped the "$this->current->locale" value and it's correct)
Route::group(['middleware' => ['web']], function () {
// put routes here
}
// on controller
use App;
use Session;
// try using these API's
Session::set('locale', 'fr');
App::setLocale(Session::get('locale'));
// The WEB middleware enables:
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
I bootstrapped my i18n component in the boot method of the "AppServiceProvider", moved that booting process to my BaseController and it worked ... Makes sense since the session will be only available after the router booted - with that 'web' middleware ...