Challenge - 5 Problems
Resource Controller Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this resource controller route?
Consider a Laravel resource controller registered as
Route::resource('photos', PhotoController::class);. What URL and HTTP method will trigger the edit method of PhotoController?Attempts:
2 left
💡 Hint
Remember the RESTful conventions for resource controllers in Laravel.
✗ Incorrect
The edit method is accessed via a GET request to /photos/{photo}/edit. This URL shows a form to edit the photo resource.
❓ state_output
intermediate2:00remaining
What is the value of $request->method() in the update method?
In a Laravel resource controller, the
update method is called when submitting an edit form. What HTTP method does $request->method() return inside the update method?Attempts:
2 left
💡 Hint
Laravel uses a special hidden input to spoof HTTP methods in forms.
✗ Incorrect
The update method responds to PUT or PATCH requests. Standard Laravel edit forms use @method('PUT'), so $request->method() returns PUT.
📝 Syntax
advanced2:00remaining
Which option correctly registers a resource controller with only index and show methods?
You want to register a resource controller but only allow the
index and show methods. Which route registration is correct?Attempts:
2 left
💡 Hint
Check Laravel's resource route options for limiting methods.
✗ Incorrect
The only method limits the resource routes to specified methods. except excludes methods but is not the best choice here. methods and filter do not exist.
🔧 Debug
advanced2:00remaining
Why does this resource controller method not receive the model instance?
Given this resource controller method:
And this route registration:
Why might
public function show(Post $post) { return view('post.show', compact('post')); }And this route registration:
Route::resource('posts', PostController::class);Why might
$post be null or cause an error?Attempts:
2 left
💡 Hint
Check the route parameter names and method parameter names for exact match.
✗ Incorrect
Laravel uses route model binding by matching the route parameter name with the method parameter name. If they differ, Laravel cannot inject the model instance.
🧠 Conceptual
expert2:00remaining
What is the main advantage of using resource controllers in Laravel?
Why do developers prefer using resource controllers instead of defining individual routes for each CRUD action?
Attempts:
2 left
💡 Hint
Think about how resource controllers help organize routes and methods.
✗ Incorrect
Resource controllers provide a clean, standardized way to create all CRUD routes with proper HTTP verbs and route names, reducing repetitive code and improving maintainability.