0
0
Laravelframework~20 mins

Creating controllers with Artisan in Laravel - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Artisan Controller Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the correct Artisan command to create a resource controller named ProductController?
Choose the exact command that generates a resource controller called ProductController using Artisan.
Aphp artisan create:controller ProductController --resource
Bphp artisan make:controller ProductController --resource
Cphp artisan make:controller ProductController -r
Dphp artisan generate:controller ProductController --resource
Attempts:
2 left
💡 Hint
The command starts with php artisan make:controller and uses a flag to create resource methods.
component_behavior
intermediate
2:00remaining
What methods are included by default in a resource controller created with php artisan make:controller --resource?
Select the set of methods that Laravel generates automatically in a resource controller.
Aindex, create, store, show, edit, update, destroy
Blist, add, save, view, modify, delete
Cget, post, put, delete, patch
Dstart, stop, pause, resume
Attempts:
2 left
💡 Hint
Think about the typical CRUD operations in Laravel resource controllers.
🔧 Debug
advanced
2:00remaining
What error will occur if you run php artisan make:controller without specifying a controller name?
Identify the error message Laravel Artisan will show when the controller name is missing.
Laravel
php artisan make:controller
AError: Missing required argument controller name
BSyntaxError: Unexpected end of command
CTypeError: Controller name must be a string
DNo error, creates a default controller named Controller
Attempts:
2 left
💡 Hint
Artisan commands require the controller name as a mandatory argument.
state_output
advanced
2:00remaining
After running php artisan make:controller Api/UserController --api, which methods will the controller contain?
Select the correct list of methods generated by the --api flag in the controller.
Aindex, create, store, show, edit, update, destroy
Bindex, create, edit, update, destroy
Clist, add, view, modify, delete
Dindex, store, show, update, destroy
Attempts:
2 left
💡 Hint
The --api flag excludes methods related to forms.
🧠 Conceptual
expert
3:00remaining
Why would you use the --invokable flag when creating a controller with Artisan?
Choose the best explanation for the purpose of the --invokable flag.
AIt creates a controller that automatically registers routes for all methods.
BIt generates a controller with all resource methods pre-filled with code.
CIt creates a controller with a single __invoke method for simple single-action controllers.
DIt creates a controller that can only be used with API routes.
Attempts:
2 left
💡 Hint
Think about controllers designed for only one action.