Laravel/PHP Articles

Articles from Laravel/PHP sites on the web

Laravel/PHP Articles
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() .

Sign Up For Our Newsletter

Each Week, We curate the top Laravel/PHP articles, jobs, events and More!

We'll send you a weekly email with the latest Laravel/PHP articles, jobs and events. Please review our Code of Conduct in the meantime. Talk to you soon!