I have a route:
Route::get(\'/setlocale/{locale}\', function($locale) {
App::setLocale($locale);
It'll only be set for that current request. You're calling the back() method, which will start a new request/response, and will reset the locale.
You should persist the value to the users session, or cookie, then use a service provider, or middleware to set the locale from the session/cookie.
Route::get('/setlocale/{locale}', function (\Illuminate\Http\Request $request, $locale) {
$request->session()->put('locale', $locale);
// or
session(['locale' => $locale]);
return back();
});
// Middleware:
public function handle($request, $next) {
App::setLocale($request->session->get('locale', 'some default locale');
// or
App::setLocale(session('locale'));
return $next($request);
}
Hope that helps.
Helpful links: