Saves a cache with the user’s login when he changes the language, for example
Cache::put(auth()->user()->username.'_lang', $linguaEscolhida);
Then it implements a middleware that defines the language for each user request, for example the Handle method of middleware would be:
public function handle($request, Closure $next)
{
if (auth()->check()) {
$lang = Cache::get(auth()->user()->username.'_lang', config('app.locale'));
App::setLocale($lang);
}
return $next($request);
}
In the example if the user is authenticated then retrieves from the cache his input to the chosen language, or returns the default locale configured in the application if there is no cache for the user.
Next set the locale with App::setLocale