Laravel is a free and open-source PHP Framework for Web Artisans based on Symfony that helps craft Web Applications following the MVC (Model View Controller) design pattern.
There are two ways to create a Laravel application, one is to use the Laravel installer. The other requires the Laravel package and for us to use a composer and a create-project command.
In this tutorial, we will use the latter.
Step by step guide on how to build your first Laravel (blog) application
Below is some information on the Laravel framework:
- Framework: Laravel
- Author: Taylor Otwell
- Initial Release Date: June 2011
- Current Version: 8 (September 8th, 2020)
- Stable Release: 8.11.2 (October 28th, 2020)
What is Laravel ?
The short version, is that Laravel is a PHP MVC Framework. The long version would be, Laravel is a free and open-source PHP Framework for Web Artisans based on Symfony.
It helps craft Web Applications following the MVC (Model View Controller) design pattern. In order for us to better understand Laravel, we will build a simple blog application with Laravel from scratch.
Requirements: To create a Laravel application you will need a few tools installed in your computer.
These tools include:
- PHP >= 7.3.
- Database (MySql).
- A localhost Web Server – In our case we’ll use WAMP (for Windows), LAMP (for Linux), or MAMP (for MacOs). This localhost webserver comes installed with latest PHP and MySQL database so you will not need to install them manually. To install either MAMP, LAMP, or WAMP go to http://ampps.com/downloads and choose the software your platform.
- Composer – This is a dependency management software for PHP. To install the composer visit https://getcomposer.org/ and download it there for your platform.
- Code editor – A code editor will be required. We recommend to use Visual Studio Code: It is free.
- A browser – Google Chrome, Edge, Safari, or Mozilla Firefox will do just fine.
- Background knowledge of the PHP Programming Language.
With our machine setup complete, it’s time to start developing.
Crafting a new Laravel application
As we mentioned before, there are two ways to create a Laravel application; one is using the Laravel installer and the other is through installing the Laravel package; and using a composer and a create-project command.
In this tutorial we will use the latter:
- Open your console and cd to www directory in your MAMP, LAMP, or WAMP installation directory.
- Type the following command:
composer create-project --prefer-dist laravel/laravel my-blogIt will create a directory called
my-blogand load all the primary Laravel files there.
Configuring our Laravel application
After installing our Laravel application we will need to configure our database for it to work.
- Go to
- Create a new Database by clicking on new (shown below in red)
- Name it
my_blogand click Create
Now that we have a database we can proceed to set up the application to work with the database.
- Open your file explorer and navigate to
- Open the
.envfile in your code editor
- Change the following in the file:-
APP_NAME key to name of your blog i.e. “My Blog”
DB_DATABASE key to database name i.e. my_blog
The final file should look like this: