Here’s how it looks in routes/web.php:Route::group(['prefix' => '{locale}'], function() { Route::get('/', function () { return view('welcome'); }); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); });All the routes above were pre-generated, we just moved them inside of our Route::group().
We add a regular-expression based rule inside of the group:Route::group([ 'prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'] ], function() { // ...
Automated Redirect of HomepageWe need to add another line to routes/web.php – to redirect the user from non-localed homepage to /en/ homepage.
So we need to add locale to the redirect URL.
In our case, all we need to do is add a locale to the route:public function redirectTo() { return app()->getLocale() .

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Community Partners