What is laravel and how laravel uses MVC
Posted By : Satyam Sharma | 31-May-2019
Basically, laravel is a structure which provides the capability to the user to create a program. It is a PHP framework, help to figure out the shape of your software and connect it with different applications program interface(APIs). The framework is just the collection of classes which provides many kinds of functionalities along with security to make developers life easier. Php have lots of frameworks but among all of them, laravel is one of the best frameworks. And the main reason for the popularity of this framework is the authentication system.
Authentication is the main key part of a web application. Laravel helps in arranging the authorization logic and control access to resources. It reduces the developer time to create an app.
How laravel use MVC?
To understand how laravel use MVC first we have to understand the MVC. So basically PHP MVC is a design pattern that separates the data and business logic from the presentation. MVC stands for the Model View & Controller.
Model is basically the collection of application data and business logic. It can be used to perform many operations like data validations, process the data and store data to the database. Data can be any kind like and static file, database, XML data or any other kind of valid resources.
The controller is the part which deals with the user's request, It accepts the user request and response as per the user requested. For example, if the user requested through URL like /index.php?products=list than the controller will load the list of product data from the model and output to the user.
The view is just for presenting the data to the user. This is the bridge for the interaction of users to our server. This is basically written in the HTML form
Now come to the point i.e how laravel using MVC. In laravel MVC used the following manners
1. Create a project in laravel.
laravel new product-store
2. Create a model by using the following command.
php artisan make:model Product
3. Connect the database using .env file then create a migration for storing the list of products. To create a migration run the following command
php artisan make:migration create_products_table
After created migration successfully just migrate the table into the database.
php artisan migrate
4. Now create a controller for handling the request.
php artisan make:controller ProductController -r
5. Now create a route to get the request and send it to the controller
6. Now create a blade template in view by which the user would request
Here user would request through the blade template then the controller would get the request and retrieve the data from the modal and send it back to the view then the user can easily see the data at frontend.
This is how the laravel uses the MVC. I hope you all would get to know how laravel uses the MVC pattern. This pattern really makes developers life much easier.
Satyam Sharma is a skilled full-stack developer, who loves to get new opportunities and learning about new technologies.