Bird
0
0

You want to display a list of products with their categories in a Laravel app using MVC. Which approach correctly follows MVC principles?

hard📝 component behavior Q15 of 15
Laravel - Basics and Architecture
You want to display a list of products with their categories in a Laravel app using MVC. Which approach correctly follows MVC principles?
AUse Controller only to render HTML, fetching done in View
BWrite SQL queries directly in the View to get products and categories
CFetch products and categories in Controller, pass to View, and display there
DPut all fetching and HTML rendering inside the Model
Step-by-Step Solution
Solution:
  1. Step 1: Recall MVC responsibilities

    Model handles data, Controller handles logic and data fetching, View handles display.
  2. Step 2: Evaluate options

    Fetch products and categories in Controller, pass to View, and display there correctly fetches data in Controller and passes it to View for display, following MVC.
  3. Final Answer:

    Fetch products and categories in Controller, pass to View, and display there -> Option C
  4. Quick Check:

    Controller fetches, View displays = Fetch products and categories in Controller, pass to View, and display there [OK]
Quick Trick: Controller fetches data; View only displays it [OK]
Common Mistakes:
  • Putting SQL in Views
  • Mixing data logic in Models with display
  • Letting Views fetch data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes