Answer the question
In order to leave comments, you need to log in
Call SetLocale on first visit to the site?
Now I have a middleware that changes the language on the site
public function handle($request, Closure $next)
{
$locale = $request->segment(1);
if (!in_array($request->segment(1), config('app.available_locales'))) {
$locale = config('app.locale');
}
app()->setLocale($locale);
return $next($request);
}
Route::get('/', function () {
return redirect(app()->getLocale());
});
Route::group([
'prefix' => '{locale}',
'where' => ['locale' => '[a-zA-Z]{2}'],
'middleware' => 'setlocale'
], function () {
...
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question