0
0
Laravelframework~10 mins

Why APIs serve modern applications in Laravel - Test Your Understanding

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

Complete the code to define a basic API route in Laravel.

Laravel
Route::[1]('/users', function () {
    return User::all();
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cview
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for fetching data.
Using 'view' which is for returning views, not API data.
2fill in blank
medium

Complete the code to return JSON data from a Laravel API controller.

Laravel
public function index() {
    $users = User::all();
    return [1]::json($users);
}
Drag options to blanks, or click blank then click option'
ARoute
BView
CResponse
DRedirect
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a View instead of JSON.
Using Redirect which is for HTTP redirects.
3fill in blank
hard

Fix the error in the API route definition to correctly use a controller method.

Laravel
Route::get('/posts', '[1]@index');
Drag options to blanks, or click blank then click option'
APostController
BpostController
CPostsController
Dpostcontroller
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase controller names.
Adding plural 's' incorrectly.
4fill in blank
hard

Fill both blanks to create a Laravel API resource route for 'products'.

Laravel
Route::[1]('products', [2]::class);
Drag options to blanks, or click blank then click option'
AapiResource
Bresource
CProductController
DProductsController
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'resource' which adds web routes.
Using plural controller names incorrectly.
5fill in blank
hard

Fill all three blanks to define a Laravel API route group with middleware and prefix.

Laravel
Route::[1](['middleware' => '[2]', 'prefix' => '[3]'], function () {
    Route::get('/orders', [OrderController::class, 'index']);
});
Drag options to blanks, or click blank then click option'
Agroup
Bauth:sanctum
Capi
Dweb
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' middleware for API routes.
Not using a route group for shared settings.