Bird
0
0

You want to create a controller named HomeController and link it to a route for /home. Which sequence of commands and code is correct?

hard📝 Application Q9 of 15
Laravel - Basics and Architecture
You want to create a controller named HomeController and link it to a route for /home. Which sequence of commands and code is correct?
ARun <code>php artisan create:controller HomeController</code> and add <code>Route::post('/home', 'HomeController@index');</code>
BRun <code>php artisan make:controller HomeController</code> and add <code>Route::get('/home', 'HomeController@index');</code>
CCreate HomeController.php manually and add <code>Route::get('/home', 'HomeController@index');</code>
DRun <code>php artisan make:controller HomeController</code> and add <code>Route::get('/home', [HomeController::class, 'index']);</code> in routes/web.php
Step-by-Step Solution
Solution:
  1. Step 1: Use correct artisan command to create controller

    The command is php artisan make:controller HomeController.
  2. Step 2: Use correct route syntax for controller action

    The string syntax Route::get('/home', 'HomeController@index') is standard and works without additional imports.
  3. Final Answer:

    Run php artisan make:controller HomeController and add Route::get('/home', 'HomeController@index'); -> Option B
  4. Quick Check:

    make:controller + string syntax route = correct [OK]
Quick Trick: Use make:controller and 'Controller@method' syntax for routes [OK]
Common Mistakes:
  • Using wrong artisan command create:controller
  • Creating controller manually
  • Using array syntax without import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes