routes in laravel code example
Example 1: named route with parameter laravel
Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => 'MenuController@listItem']);
route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);
Example 2: route() and with() in laravel
Route::get('user/{id}/profile', function ($id) {
})->name('profile');
$url = route('profile', ['id' => 1, 'photos' => 'yes']);
Example 3: laravel route
# Using Request
Route::get('user/{name}', function (Request $request) {
return $request->route('name');
});
Example 4: laravel route
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
Example 5: laraval routing
Route::redirect('/here', '/there', 301);
Example 6: laraval routing
use App\Http\Controllers\UserController;
use App\Models\User;
Route::get('/users/{user}', [UserController::class, 'show']);
public function show(User $user)
{
return view('user.profile', ['user' => $user]);
}