MVC concept in Laravel framework

hendra kusuma
Zetta Tech
Published in
3 min readApr 13, 2023

Hello everyone, back again with me. I want to share knowledge about the concept of MVC in the Laravel framework,

Background
In this case, currently, I’m on learning the PHP backend framework Laravel on my Bootcamp,

Task

I want to share about the MVC concept and how to use it in Framework Laravel

Getting Started

first, I assume you already understand the installation of text editors’ Visual Studio Code and have done it to the installed composer. composer can install on https://getcomposer.org/.

MVC is the backend structure in website development. MVC is Model, View, Controller. A ‘model’ is a structure within the MVC concept that is useful for configuring connection relationships into a database. ‘View’ is a structure in the MVC concept that is useful for managing the display in a website, where later there will be inserted blade files.php which are the same as HTML files on the front end. There will be many configurations. The third is the Controller, this controller file is useful for configuring as a brain to manage the course between the model and the view and is also connected to file routing outside the MVC concept, routing is used as a path/route in web pages

the first thing we do is import the Laravel framework with the command ‘composer create-project laravel/laravel test-MVC’. wait until finish download and setup and Laravel project ready to develop.

now you can do command `php artisan make:model books`, that command to make file books in folder model,

Not all code must be understood, but what needs to be considered in the middle code is only to provide code input as shown above. after that, you can use command `php artisan make:controller homeController` to make homeController file in folder controller, we actualy use controller as a brain,

in the controller we create index function which isi redirect to ‘index’ in folder View.

in view we create new file home.blade.php,

blade.php is the file only in framework laravel has few improvement and better than ordinary file HTML. if we want to call a function on something we just call @if or ifend . now in file router we can give access.

we can run the server with command “php artisan serve”

server is running and connected

For additional information on the ‘Model’ structure, if we want to connect to the ‘View’, we must first create a form to retrieve data from the client in file blade.php so that it can be connected to the database. For just testing the database we can use dummy data for database testing purposes with the name ‘data seeder’, and for automation of creating tables in the database we can use ‘migration’.

in my next article we will continue about migration and data seeder.

okay thanks for your read, see you in the next post :)

Github :https://github.com/Hendra-Kusuma
Email:
hendrakusuma.vegas@gmail.com

--

--