The first line always returns 'en' as it is the default. When I do Session:get('language') returns null.
Session Data Not Saving When Called in Router, I want to know why!
I have this simple code in routes.php. It is meant to switch language to Spanish. But saved information in the session is gone by the next page load and session is empty.
$language = Session::get('language',Config::get('app.locale')); App::setLocale($language);
Route::get('/', function () { return view('page.home'); })->name('home');
Route::get('contact', function () { return view('page.contact'); })->name('contact');
Route::get('switchtospanish', function () { //session(['language' => 'es']); Session::put('language','es'); Session::save(); return back(); })->name('switchtospanish');
There aren't any errors. But I do not understand why is this not working. I saw different ways to do this online (like making a middleware) but to better understand, I want to know why is this not working.
Please or to participate in this conversation.