Route::get('/home', function () { return view('home'); })->name('home'); Route::get('/', function () { return redirect()->route('home'); });
Route::get('/product/{id}', function ($id) { return view('product', ['id' => $id]); })->name('product'); Route::get('/products/{id}', function ($id) { return redirect()->route('product', ['id' => $id]); });In this example, we define a named route called "product" that takes an "id" parameter and returns a view called "product.blade.php" with the ID passed in as a variable. Then, we define a new route that redirects any user visiting "/products/{id}" to the "product" route with the same ID as a parameter. The PHP Redirect to_route function is part of the Laravel framework, specifically the Routing package.