Laravel is a very powerful framework that follows the MVC structure. It is designed for web developers who need a simple, elegant yet powerful toolkit to build a fully-featured website.
This tutorial explains the basic use of this framework by building a simple blogging system. But before we start, there are some apps we need to install.
XAMPP is a free and open-source cross-platform web server solution stack package developed by Apache Friends. It contains MySQL, phpMyAdmin, PHP and Apache server.
It has combined everything you need for PHP web development in one place and spares you the time for installing and configuring each of them individually.
The good news is, if you are a student, you will be qualified for a free copy with your student email.
Composer is a dependency manager for PHP, and it helps you install Laravel and all the other dependencies that you need for building a website. Remember, you need to install XAMPP or PHP first, or the composer installer will not be able to find
First, create a new empty PHP project in PhpStorm. In this tutorial, I’ll name it “Laravel_Blog”.
Now we need to install Laravel for our project. Open “Terminal”, it should go to the root directory of the project. Run the following commands.
Download the Laravel installer:
composer global require laravel/installer
Create a new Laravel app:
If you are planning to create multiple apps, then put each app into an independent folder, for example:
laravel new blog laravel new gallery
This process will take a few minutes to complete.
Once it is done, this is what you should get:
Here I will only introduce the directories that we need to use in this tutorial since some might be a little confusing for beginners. If you are interested, you can read the Official Documentation, which explains the function of each directory in detail.
This folder contains the entire source code of our project. It includes events, middleware, exceptions and so on. But, for now, we only care about models and controllers.
As the name impies, it stores all configuration files for our project.
database directory is where we put all the seeds and migration files. They determine the structure of the database. If you wish, you may also use this directory to hold an SQLite database. But I don’t recommend using SQLite for huge projects.
This directory holds the index.php file, which is the entry point for all requests. Also, we need to put all static files (CSS and JS) into this folder.
route directory contains all URL declarations for our project. By default, there are four route files:
channels.php. For this tutorial, we only need to understand
Here, you will find all Eloquent models. The models do not have an individual folder, but developers can place them in one if they choose.
And finally, this is where we put all the controllers for our project. All of the logic to handle requests entering your application will be placed in this directory.
Now we can run the built-in local development server:
php artisan serve
Or we can use the Apache server from XAMPP, but you might need to change the “
DocumentRoot” setting in the configuration file.
DocumentRoot and change its path to the
public folder of your project. Once you are done, restart the server. Open the browser and go to http://localhost/
Next, we’ll talk about URLs, routes, and the MVC (Model-View-Controller) architecture that is commonly used by most web frameworks.