route with optional parameter laravel code example
Example 1: route() and with() in laravel
Route::get('user/{id}/profile', function ($id) {
})->name('profile');
$url = route('profile', ['id' => 1, 'photos' => 'yes']);
Example 2: route optional parameter laravel
Route::get('user/{name?}', function ($name = null) {
return $name;
});
Route::get('user/{name?}', function ($name = 'John') {
return $name;
});
Example 3: laravel route optional parameter
Route::get('user/{name?}', function ($name = null) {
return $name;
});
Route::get('user/{name?}', function ($name = 'John') {
return $name;
});
Example 4: laravel route
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
});