Challenge - 5 Problems
Resource Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the HTTP method and URI for the 'edit' action in a Laravel resource route?
Given a Laravel resource route defined as
Route::resource('photos', PhotoController::class);, what is the HTTP method and URI that corresponds to the 'edit' action?Attempts:
2 left
💡 Hint
The 'edit' action shows a form to edit an existing resource and uses GET.
✗ Incorrect
In Laravel resource routes, the 'edit' action uses the GET method and the URI pattern is /resource/{id}/edit. So for 'photos', it is GET /photos/{photo}/edit.
📝 Syntax
intermediate2:00remaining
Which option correctly registers a resource route for 'posts' with only 'index' and 'show' actions?
You want to register a resource route for 'posts' but only want to include the 'index' and 'show' actions. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Use the 'only' method with an array of action names.
✗ Incorrect
The 'only' method accepts an array of action names to include. Option D uses the correct syntax. Option D is invalid because 'only' expects an array, not multiple arguments.
❓ state_output
advanced2:00remaining
What is the route name generated for the 'destroy' action in a resource route for 'users'?
If you define
Route::resource('users', UserController::class);, what is the name of the route generated for the 'destroy' action?Attempts:
2 left
💡 Hint
Laravel uses the resource name plus the action name for route names.
✗ Incorrect
Laravel generates route names by combining the resource name and the action name separated by a dot. For 'destroy' action on 'users', the route name is 'users.destroy'.
🔧 Debug
advanced2:00remaining
Why does this resource route registration cause a runtime error?
Consider this code:
Route::resource('products', ProductController::class)->only('index', 'show'); When running, it throws an error. What is the cause?Attempts:
2 left
💡 Hint
Check the argument type passed to 'only'.
✗ Incorrect
The 'only' method expects an array of action names. Passing multiple string arguments without an array causes a runtime error.
🧠 Conceptual
expert2:00remaining
Which HTTP methods are included by default in a Laravel resource route?
When you define
Route::resource('comments', CommentController::class);, which HTTP methods are automatically handled by the generated routes?Attempts:
2 left
💡 Hint
Think about all CRUD operations and their HTTP verbs.
✗ Incorrect
Laravel resource routes cover all CRUD operations: GET for index/show/edit/create, POST for store, PUT/PATCH for update, and DELETE for destroy.