Connect with us

Mastering Laravel MVC (Model View Controller) and Folder Structures

kizinho

Published

on

Follow
DEVELOPER PROGRAMMING: Mastering Laravel MVC (Model View Controller) and Folder Structures [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl

Hi, folks, we have successfully created the laravel project in the last class, if you missed it go back and create a new laravel project here.

Before going to MVC (Model View Controller) let's serve up the project for development purposes using the following command

php artisan serve

output result

Starting Laravel development
 server: http://127.0.0.1:8000

incase if you want to serve your project from a different port number, use the following command below

php artisan serve --port=8070

output result

Starting Laravel development 
server: http://127.0.0.1:8070


your project will be live on http://127.0.0.1:8000, you can now visit your browser and enter the live project URL, it will give you the following new fresh interface below.



if you encountered the following error click on the Generate app Key or use the laravel artisan command below

php artisan key:generate

refresh your page to see the new interface


Hurray! that's cool


We will talk more about the laravel PHP artisan command and composer command later in the class as we progress.


Model View Controller (MVC) is a software architecture that separates the login and flows in your application for easy maintaining and collaborations.

  • Model (M): A Model is a representation of a real-life instance or object in our codebase which basically deals with database interactions
  • View(V): The View represents the interface through which the user interacts with your application which basically deals with HTML, CSS, JAVASCRIPT, when a user visits your products what they see or click on is what view offers to them.
  • Controller(C): When a user takes an action, the Controller handles the action and updates the Model if necessary. The controller basically deals with the functions that you have written which passes the return data to the View

Let's move into the new project folder structure, you have to use your desired code editor and open your new project, am using Netbeans IDE.

From the project structure folders I will pick up a few folders that we will be using the form now, others will be used as the class progresses.

  1. App folder
  2. Resources folder
  3. Routes folder

App folder which consisted of another subfolder below

Our main focus is to see the MVC in action, inside the App folder I will pick Http and Models.

Http contains the controller folder where all the functions of the project will live-in and Models will be used to store as well as retrieve information from the database which is based on ORM, you will understand ORM as we progress.

Http folder below


Resources folder

Inside the Resources folder, we have the Views folder which will contain the webpages for the project eg index, contacts etc but this view is based on the blade engine, when saving a page inside the views, we save it like the index.blade.php, contactus.blade.php, all in lowercase.


Routes folder

Routes folder contains many PHP files but we are focusing on web.php. With web.php is where we are creating a request URL to the application, eg http://127.0.0.1:8000/contactus etc.


Hurray! you have mastered the MVC and the default Laravel folders, congrats you can now move to the next class here

Click Here To Comment


site


kizinho

Adike Kizito is a top-rated software developer, blogger, sports, and entertainment lover. He is the CEO of these popular websites Naijacrawl.com and Mp3ager.com. He operates his software developing task through Kizzsoft.com,... Read More

Continue Reading
1 Comment

1 Comment

  1.   David Enabs

    This is was great!
    Thanks boss


Leave a Reply

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

Laravel 9.18.0 New Features Detailed

kizinho

Published

on

DEVELOPER PROGRAMMING: Laravel 9.18.0 New Features Detailed [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Laravel 9.18.0 comes with a new feature that you will love to upgrade and use, the new features come with 4 main features shipped.Rule objectsQuery timeAttachable objects Nested eager load syntaxRule objects rules that make it simpler to define custom validation rules using simple, single method invokable objects. Very similar API to Closure rules.Query timeintroduced a new method that invokes a closure if cumulative time you spend querying the database during a req...
Continue Reading

How to Customize Laravel Validator Error with Reusable Functions

kizinho

Published

on

DEVELOPER PROGRAMMING: How to Customize Laravel Validator Error with Reusable Functions [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Laravel is a powerful PHP framework that helps you to build a web application quickly. Laravel is very easy to use and maintain the codebase, I will advise using the latest version of laravel when building a new project.Read Also : How to solve This page isn’t working HTTP ERROR 500 in LaravelToday I will show how you can customize the laravel validator error and reused it when validating your requests and return a nice error message to the user.Example functionsuse...
Continue Reading

How to Upgrade Laravel Application from Version 5 to latest Version 8

kizinho

Published

on

DEVELOPER PROGRAMMING: How to Upgrade Laravel Application from Version 5 to latest Version 8 [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Hi, Folks, have you feels like Laravel continuous released of new versions has let you down and you can't cope with it any longer, don't worry this article is a quick guide for you, that has I upgrade naijacrawl from 5.8 to the latest 8 versions.All you need to know before upgrading your old laravel.External packages might fail to install, so isolate your packages firstInstall fresh laravel applicationThank me later.First, all you will do to be successful when upgra...
Continue Reading

Latest


Download Naijacrawl App today

Fastest way to read on the go

Download the Naijacrawl App.