Route Parameters

Capture segments of the URI within your route

#Required parameters

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

With dependency injection

use Illuminate\Http\Request;
Route::get('/user/{id}', function (Request $request, $id) {
    return 'User '.$id;
});

#Optional Parameters

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