Bird
0
0

Given this single action controller code, what will be the output when accessed?

medium📝 component behavior Q13 of 15
Laravel - Controllers
Given this single action controller code, what will be the output when accessed?
class WelcomeController {
    public function __invoke() {
        return 'Hello, Laravel!';
    }
}
AHello, Laravel!
BError: Method not found
CEmpty response
D404 Not Found
Step-by-Step Solution
Solution:
  1. Step 1: Understand __invoke method behavior

    The __invoke method runs when the controller is called as a single action, returning the string 'Hello, Laravel!'.
  2. Step 2: Predict the output

    Since the method returns a string, the response will be that string displayed.
  3. Final Answer:

    Hello, Laravel! -> Option A
  4. Quick Check:

    __invoke returns string = 'Hello, Laravel!' [OK]
Quick Trick: __invoke returns output directly as response [OK]
Common Mistakes:
  • Expecting an error due to missing method name
  • Thinking it returns empty or 404
  • Confusing with multi-method controllers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes