0
0
Laravelframework~20 mins

Resource controllers in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Resource Controller Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
APUT /photos/{photo}/edit
BPOST /photos/{photo}/edit
CGET /photos/{photo}/edit
DGET /photos/edit/{photo}
Attempts:
2 left
💡 Hint
Remember the RESTful conventions for resource controllers in Laravel.
state_output
intermediate
2: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?
APUT
BPATCH
CGET
DPOST
Attempts:
2 left
💡 Hint
Laravel uses a special hidden input to spoof HTTP methods in forms.
📝 Syntax
advanced
2: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?
ARoute::resource('posts', PostController::class)->except(['create', 'edit']);
BRoute::resource('posts', PostController::class)->filter(['index', 'show']);
CRoute::resource('posts', PostController::class)->methods(['index', 'show']);
DRoute::resource('posts', PostController::class)->only(['index', 'show']);
Attempts:
2 left
💡 Hint
Check Laravel's resource route options for limiting methods.
🔧 Debug
advanced
2:00remaining
Why does this resource controller method not receive the model instance?
Given this resource controller method:
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?
AThe model class <code>Post</code> does not exist.
BThe route parameter name does not match the method parameter name.
CThe controller method is missing a return statement.
DThe route is missing a middleware for authentication.
Attempts:
2 left
💡 Hint
Check the route parameter names and method parameter names for exact match.
🧠 Conceptual
expert
2: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?
AThey automatically generate all standard CRUD routes with consistent naming and HTTP methods.
BThey allow defining routes without any controller methods.
CThey disable CSRF protection for all routes automatically.
DThey force all routes to use the GET method for simplicity.
Attempts:
2 left
💡 Hint
Think about how resource controllers help organize routes and methods.