Laravel for Beginners – Learn to Build Full-Stack Web Apps

Loading video...

Route Required Parameters

Routing

Required Parameters

This code defines a route with required parameter id

Route::get("/product/{id}", function(string $id) {
    return "Product ID=$id";
});

Matches the following routes

  • /product/1
  • /product/test
  • /product/{any_string}

You can also define multiple route parameters in the following way.

Route::get("{lang}/product/{id}", function(string $lang, string $id) {
    return "Product Lang=$lang. ID=$id";
});

Matches the following routes

  • /en/product/1
  • /ka/product/test
  • /{any_string}/product/{any_string}
Route::get("{lang}/product/{id}/review/{reviewId}", function(string $lang, string $id, string $reviewId) {
    return "Product Reviews Lang=$lang. ID=$id. ReviewID=$reviewId";
});

Matches the following routes

  • /en/product/1/review/123
  • /ka/product/test/review/foo
  • /{any_string}/product/{any_string}/review/{any_string}

Discussion

Sign in to join the discussion.

No comments yet. Be the first to start the discussion!