0
0
Laravelframework~10 mins

API resource controllers in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a resource controller using Artisan.

Laravel
php artisan make:controller [1] --resource
Drag options to blanks, or click blank then click option'
Aresource
Bmake:controller
CUserController
Dapi
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'make:controller' as the controller name.
Omitting the controller name.
Using 'resource' as the controller name.
2fill in blank
medium

Complete the route definition to register a resource controller for 'users'.

Laravel
Route::[1]('users', UserController::class);
Drag options to blanks, or click blank then click option'
Apost
Bresource
Cget
Dcontroller
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' or 'post' instead of 'resource'.
Using 'controller' which is for single action controllers.
3fill in blank
hard

Fix the error in the method signature for updating a resource in the controller.

Laravel
public function update(Request [1], $id)
Drag options to blanks, or click blank then click option'
A$request
B$Request
CRequest
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name without a variable.
Omitting the dollar sign for the variable.
4fill in blank
hard

Fill both blanks to return a JSON response with the updated user data and a 200 status code.

Laravel
return response()->json([1], [2]);
Drag options to blanks, or click blank then click option'
A$user
B200
C201
DUser::all()
Attempts:
3 left
💡 Hint
Common Mistakes
Using User::all() which returns all users instead of the updated one.
Using status code 201 which is for resource creation.
5fill in blank
hard

Fill all three blanks to define a route group with 'api' middleware and register a resource controller for 'posts'.

Laravel
Route::middleware('[1]')->group(function () {
    Route::[2]('[3]', PostController::class);
});
Drag options to blanks, or click blank then click option'
Aauth:api
Bresource
Cposts
Dweb
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' middleware instead of 'auth:api'.
Using 'get' or 'post' instead of 'resource' for route registration.
Using 'post' instead of 'posts' as the route URI.