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
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
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
- 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.
- App folder
- Resources folder
- 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
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 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