Bird
0
0

You want to create a route that handles URLs like '/product/123/review/456' and runs a function with both IDs. Which route definition is correct?

hard📝 component behavior Q8 of 15
Laravel - Routing
You want to create a route that handles URLs like '/product/123/review/456' and runs a function with both IDs. Which route definition is correct?
ARoute::get('/product/{productId}/review/{reviewId}', function ($productId, $reviewId) { return "Product $productId, Review $reviewId"; });
BRoute::get('/product/{productId}/review', function ($productId, $reviewId) { return "Product $productId, Review $reviewId"; });
CRoute::get('/product/review/{reviewId}', function ($productId, $reviewId) { return "Product $productId, Review $reviewId"; });
DRoute::get('/product/{productId}/review/{reviewId}', function () { return "Product $productId, Review $reviewId"; });
Step-by-Step Solution
Solution:
  1. Step 1: Match URL pattern with parameters

    The URL has two parameters: productId and reviewId in the correct order.
  2. Step 2: Ensure function accepts both parameters

    The function must accept $productId and $reviewId to use them inside.
  3. Final Answer:

    Route::get('/product/{productId}/review/{reviewId}', function ($productId, $reviewId) { return "Product $productId, Review $reviewId"; }); -> Option A
  4. Quick Check:

    Multiple route params need matching function args [OK]
Quick Trick: Each URL param needs a function argument [OK]
Common Mistakes:
  • Missing one parameter in URL or function
  • Incorrect URL pattern order
  • Not passing parameters to function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes