0
0
Laravelframework~10 mins

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 register a resource controller route in Laravel.

Laravel
Route::[1]('photos', PhotoController::class);
Drag options to blanks, or click blank then click option'
Aresource
Bget
Cpost
Dview
Attempts:
3 left
💡 Hint
Common Mistakes
Using get or post instead of resource.
Trying to manually define each route instead of using resource.
2fill in blank
medium

Complete the method name to show the form for creating a new resource.

Laravel
public function [1]()
{
    return view('photos.create');
}
Drag options to blanks, or click blank then click option'
Acreate
Bedit
Cstore
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using store instead of create for showing the form.
Confusing edit with create.
3fill in blank
hard

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

Laravel
public function update(Request $request, [1] $photo)
{
    // update logic
}
Drag options to blanks, or click blank then click option'
Aint
BPhoto
Cstring
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or string instead of the model class.
Not type-hinting the parameter at all.
4fill in blank
hard

Fill both blanks to define a route that only includes index and show methods.

Laravel
Route::resource('articles', ArticleController::class)->[1](['[2]', 'show']);
Drag options to blanks, or click blank then click option'
Aonly
Bexcept
Cindex
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using except instead of only.
Putting wrong method names in the array.
5fill in blank
hard

Fill all three blanks to define a resource route with a custom parameter name.

Laravel
Route::resource('users', UserController::class)->parameters(['users' => '[1]']);

public function show([2] $[3])
{
    // show user
}
Drag options to blanks, or click blank then click option'
Amember
BUser
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Not matching the parameter name in the method signature.
Using wrong case for class or variable names.