Bird
0
0

How can you generate a URL for a named route with parameters?

hard📝 Application Q9 of 15
Laravel - Routing
How can you generate a URL for a named route with parameters?
Given:
Route::get('/user/{id}', fn($id) => 'User '.$id)->name('user.show');

Which code correctly generates the URL for user id 5?
Aroute('user.show')->param(5)
Broute('user.show', 5)
Croute('user.show')->with('id', 5)
Droute('user.show', ['id' => 5])
Step-by-Step Solution
Solution:
  1. Step 1: Recall route() helper with parameters

    To pass parameters, route() accepts an associative array with parameter names and values.
  2. Step 2: Identify correct syntax

    route('user.show', ['id' => 5]) correctly passes ['id' => 5] to route() to generate URL with id=5.
  3. Final Answer:

    route('user.show', ['id' => 5]) -> Option D
  4. Quick Check:

    Pass parameters as array in route() [OK]
Quick Trick: Pass parameters as array: route('name', ['param' => value]) [OK]
Common Mistakes:
  • Passing parameter as single value without array
  • Using non-existent methods like with() or param()
  • Confusing parameter names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes