MVC

What is it?

MVC (Model-View-Controller) is an architectural pattern that separates application logic into three interconnected components. The Model manages data and business logic, the View handles the display and user interface, and the Controller processes user input and coordinates between Model and View. This separation makes code more organized, testable, and maintainable across teams.

Practical example

In a Laravel blog application, the Post model defines the database structure and relationships like belongsTo User for the author. The PostController handles HTTP requests: the index method fetches all posts and passes them to a view, the store method validates form input and creates new posts. Blade view templates display the data with HTML and simple PHP logic for loops and conditionals.

Test your knowledge

What does the Controller do in MVC?

Ask Lex
Lex knows the context of this term and can give targeted explanations, examples, and extra context.
Tip: Lex replies briefly in the widget. For more detail, go to full screen mode.

Quick links