Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a GET API route that returns a welcome message.
Laravel
Route::[1]('/welcome', function () { return response()->json(['message' => 'Welcome to the API']); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for fetching data.
Confusing HTTP methods.
✗ Incorrect
The GET method is used to retrieve data from the server. Here, Route::get defines a route that responds to GET requests.
2fill in blank
mediumComplete the code to define a POST API route that calls the UserController's store method.
Laravel
Route::[1]('/users', [UserController::class, 'store']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for creating data.
Mixing up controller method names.
✗ Incorrect
POST method is used to send data to the server to create a new resource. Here, the route calls the store method to add a new user.
3fill in blank
hardFix the error in the route definition to correctly define a route that updates a user by ID using PUT method.
Laravel
Route::[1]('/users/{id}', [UserController::class, 'update']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of PUT for updating data.
Forgetting to include the {id} parameter in the route.
✗ Incorrect
PUT method is used to update existing resources. The route uses PUT to update a user by their ID.
4fill in blank
hardFill both blanks to define a route group with middleware 'auth:sanctum'.
Laravel
Route::[1](['middleware' => '[2]'], function () { // API routes here });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Route::get instead of Route::group for grouping.
Incorrect middleware name.
✗ Incorrect
Route::group defines a group of routes with shared attributes. Here, the middleware 'auth:sanctum' protects the routes inside the group.
5fill in blank
hardFill both blanks to define a resource route for 'posts' using PostController with only 'index' and 'show' methods.
Laravel
Route::resource('posts', PostController::class)->only(['[1]', '[2]']);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including methods like 'store' or 'update' when only 'index' and 'show' are needed.
Misspelling method names.
✗ Incorrect
The resource route defines routes for controller methods. Using only(['index', 'show']) limits routes to listing and showing posts.