A
A
adam_carraway2020-01-12 12:39:16
Laravel
adam_carraway, 2020-01-12 12:39:16

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);
    }

And here is the routing
Route::get('/', function () {
    return redirect(app()->getLocale());
});

Route::group([
    'prefix' => '{locale}',
    'where'  => ['locale' => '[a-zA-Z]{2}'],
    'middleware' => 'setlocale'
], function () {
...
});

How to make it so that when you first enter the site, not the default language is set, but some other?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question