What is MVC(Model, View, Controller) and Routes?
Laravel is an MVC framework. MVC stands for Model-View-Controller.
A model is a representation of your data. The Models represent the data and business logic for your application. It’s where you define the structure of your data and how it interacts with the rest of your application. For example, in our application, we will record employee data. Therefore, we are going to have a model of an employee.
Each employee consists of:
- Name of the employee
- Department of the employee
- The joining date of the employee
- Salary of the employee
We’ll have a model representing and storing this data in the database.
A view is the presentation layer. For example, we’ll need a form so that use can enter his data to create a new registration. This form code is a view.In Laravel, we use a special templating language called Blade.
Blade files are names in this format: “[name].blade.php”
resources-views-[name].blade.php
Controller: The controller acts as a bridge between the Model and View. It processes user inputs, updates the model, and generates the appropriate view. Controllers are how you control things. Hence the name. For example, you can show the list of registered users.
The controller will use the purchase model to fetch a list of purchases. Then it will pass this data to the view, so it can show it to the user.
app-http-controllers-nameOfController
Routes: Routes define how URLs map to your application’s controllers and actions. In other words, they define which page the user will see when they access the specific URL.