Bird
0
0

Consider this route:

medium📝 component behavior Q5 of 15
Laravel - Routing
Consider this route:
Route::get('/user/{id}', function ($id) { return 'User ID: ' . $id; });

What will be the output when visiting '/user/42'?
A404 Not Found
BUser ID: {id}
CUser ID: 42
DUser ID:
Step-by-Step Solution
Solution:
  1. Step 1: Understand route parameters

    The route defines a parameter {id} which is passed to the closure as $id.
  2. Step 2: Substitute the URL segment into the parameter

    Visiting '/user/42' sets $id = 42, so the returned string is 'User ID: 42'.
  3. Final Answer:

    User ID: 42 -> Option C
  4. Quick Check:

    Route parameter {id} passed as $id [OK]
Quick Trick: Route parameters become function arguments [OK]
Common Mistakes:
  • Not using $id in closure
  • Expecting literal {id} in output
  • Missing route parameter in URL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes