Why MVC Design pattern?
The Model-View-Controller (MVC) software architectural pattern separates an application into three main logical components: the model, the view, and the controller, it design pattern decouples these major components allowing for efficient code reuse and parallel development.
How MVC Works?
Think in these logical components as layers of your application.
It directly manages the data, logic and database rules of the application. It is according to commands from the controller and can be displayed in the view. In Laravel the model also will be responsible by relationships of your application.
Think in view as the output of your application, a view can be any output representation of information, such as a chart or a diagram.
The controller, accepts input and converts it to commands for the model or view, here you have validations the business operation logic.
As we saw before in the first image of this post, have some interactions under these layers.
- When the user request something (It can be by HTTP requests or terminal commands for example) the framework will get the correct route.
- When the framework finds the correct route, it usually will be assigned to HTTP Controller or a command.
- The controller can return a lot of things, interacting with model or not, and can be displayed in views.
- Usually a view will be rendered to users in browser, however if the controller don’t return a view, it will return by default as a JSON.
Notes to remember
MVC is very important for simultaneous development, it have low coupling, is easy to maintain and integrate and we can have multiple-views for models.
The images was extracted of internet, some links are important to understand more about this pattern.