set parameter in route laravel code example

Example 1: route optional parameter laravel

Route::get('user/{name?}', function ($name = null) {
    return $name;
});

Route::get('user/{name?}', function ($name = 'John') {
    return $name;
});

Example 2: laravel routes return view in web.php

Route::get("/page", function(){
   return View::make("dir.page");
});

Example 3: route() and with() in laravel

Route::get('user/{id}/profile', function ($id) {
    //
})->name('profile');

$url = route('profile', ['id' => 1, 'photos' => 'yes']);

// /user/1/profile?photos=yes

Example 4: laravel route

Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});

Example 5: laravel route optional parameter

Route::get('/sample/{param?}', 'SampleController@index');

Tags:

Html Example