Bird
0
0

Why does this code cause an error?

medium📝 Debug Q6 of 15
Laravel - Controllers
Why does this code cause an error?
Route::resource('tasks', 'TaskController');
AController should be passed as a class reference, not a string
BRoute::resource does not accept two arguments
CThe URI 'tasks' is invalid
DTaskController must be registered in a service provider
Step-by-Step Solution
Solution:
  1. Step 1: Check correct parameter type for Route::resource

    Modern Laravel requires controller as a class reference using ::class.
  2. Step 2: Identify why string causes error

    Passing controller as string causes Laravel to fail resolving the class.
  3. Final Answer:

    Controller should be passed as a class reference, not a string -> Option A
  4. Quick Check:

    Controller parameter must be class reference [OK]
Quick Trick: Use ControllerName::class, not string, in Route::resource [OK]
Common Mistakes:
  • Passing controller as string
  • Wrong number of arguments
  • Assuming URI is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes