A break in Laravel to understanding MVC architecture

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.

Model

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.

View

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.

Controller

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.

 

  1. When the user request something (It can be by HTTP requests or terminal commands for example) the framework will get the correct route.
  2. When the framework finds the correct route, it usually will be assigned to HTTP Controller or a command.
  3. The controller can return a lot of things, interacting with model or not, and can be displayed in views.
  4. 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.

Links:
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
https://www.tutorialspoint.com/mvc_framework/mvc_framework_introduction.htm
http://laravelbook.com/laravel-architecture/

 

Share this!




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *

*