Bird
0
0

What happens if you define multiple methods in a single action controller and register it as Route::get('/test', TestController::class);?

medium📝 Predict Output Q5 of 15
Laravel - Controllers
What happens if you define multiple methods in a single action controller and register it as Route::get('/test', TestController::class);?
AThe first method defined is called automatically
BLaravel throws an error about multiple methods
COnly the __invoke() method is called when the route is accessed
DYou must specify the method name in the route
Step-by-Step Solution
Solution:
  1. Step 1: Recall single action controller behavior

    Laravel calls the __invoke() method automatically when the controller class is used in route.
  2. Step 2: Multiple methods do not affect __invoke() call

    Other methods are ignored unless explicitly called.
  3. Final Answer:

    Only __invoke() method is called -> Option C
  4. Quick Check:

    Multiple methods present = __invoke() called only [OK]
Quick Trick: Only __invoke() runs in single action controller route [OK]
Common Mistakes:
  • Expecting error on multiple methods
  • Assuming first method runs
  • Forgetting to use __invoke()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes