Bird
0
0

Why should controller methods avoid directly accessing the database and instead use models or services?

hard📝 Conceptual Q10 of 15
Laravel - Controllers
Why should controller methods avoid directly accessing the database and instead use models or services?
ABecause Laravel does not allow database access in controllers
BTo keep controllers focused on handling requests and responses
CTo improve performance by skipping database queries
DBecause models cannot be used inside controllers
Step-by-Step Solution
Solution:
  1. Step 1: Understand MVC separation

    Controllers handle input/output, models handle data logic.
  2. Step 2: Benefits of separation

    This keeps code organized, easier to maintain and test.
  3. Final Answer:

    To keep controllers focused on handling requests and responses -> Option B
  4. Quick Check:

    Controller responsibility separation [OK]
Quick Trick: Keep controllers clean by using models/services for data [OK]
Common Mistakes:
  • Thinking Laravel forbids DB access in controllers
  • Believing skipping DB improves performance
  • Assuming models can't be used in controllers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes