0
0
Laravelframework~20 mins

Resource routes in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Resource Route Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
AGET /photos/{photo}/edit
BPOST /photos/{photo}/edit
CGET /photos/edit/{photo}
DPUT /photos/{photo}/edit
Attempts:
2 left
💡 Hint
The 'edit' action shows a form to edit an existing resource and uses GET.
📝 Syntax
intermediate
2: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?
ARoute::resource('posts', PostController::class)->except(['index', 'show']);
BRoute::resource('posts', PostController::class)->include(['index', 'show']);
CRoute::resource('posts', PostController::class)->only('index', 'show');
DRoute::resource('posts', PostController::class)->only(['index', 'show']);
Attempts:
2 left
💡 Hint
Use the 'only' method with an array of action names.
state_output
advanced
2: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?
Ausers.delete
Busers.destroy
Cusers.remove
Dusers.destroyUser
Attempts:
2 left
💡 Hint
Laravel uses the resource name plus the action name for route names.
🔧 Debug
advanced
2: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?
AProductController must be imported with a 'use' statement.
BThe resource name 'products' must be singular, not plural.
CThe 'only' method requires an array, not multiple string arguments.
DThe 'only' method is not available on resource routes.
Attempts:
2 left
💡 Hint
Check the argument type passed to 'only'.
🧠 Conceptual
expert
2: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?
AGET, POST, PUT/PATCH, DELETE
BGET and POST only
CGET, POST, DELETE only
DGET, POST, PUT, PATCH, DELETE, OPTIONS
Attempts:
2 left
💡 Hint
Think about all CRUD operations and their HTTP verbs.