How to specify a language for a single request in Lumen?
I need to show a simple page (view) in the user's language, but it's not so easy in Lumen.
As long as Lumen has no sessions support I can't just log in a user to use his locale:
Auth::login($user);
or
Auth::onceUsingId($user->id);
Any ideas?
You can use a middleware to set the language of the user
public function handle(Request $request, $next)
{
$user = $request->user();
app('translator')->setLocale($user->locale);
}
Documentation: https://lumen.laravel.com/docs/7.x/middleware
Please or to participate in this conversation.