Part 1: Installing Laravel
The first thing that we need to do is get the latest version of Laravel using composer. In case you did not know, The Laravel framework utilizes Composer for installation and dependency management. If you haven’t already installed composer, start by installing Composer. Once you have composer installed, you are ready to install Laravel. This is done with the following command:
composer create-project laravel/laravel burgerpedia
This command will download and install a fresh copy of Laravel in a new burgerpedia
folder within your current directory. At the time of this writing, Laravel 5.3.0 is the latest copy of Laravel. It takes a bit of time to download a fresh install, so you will have to wait a bit while laravel gets installed.
Now that we have a fresh copy of laravel, we need to download and install the various dependencies of the framework. This is done by typing the following command in the root path of the newly created project.
composer install
You need to do this in the root of your manually created project directory, otherwise you might get an error saying “Composer could not find a composer.json file in the directory”. The composer.json file describes the dependencies of a project and may contain other metadata as well. When you type ‘composer install’, this file is read and all dependencies are installed.
Now that Laravel is installed, we can have a look at the generated filesystem used for laravel. It looks like so:
Some of the important directories that you should be aware of are:
- The database directory contains your database migration and seeds. If you wish, you may also use this directory to hold an SQLite database.
- The app directory, as you might expect, contains the core code of your application. We’ll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.
- The bootstrap directory contains files that bootstrap the framework and configure autoloading. This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files.
- The config directory, as the name implies, contains all of your application’s configuration files. It’s a great idea to read through all of these files and familiarize yourself with all of the options available to you.
- The public directory contains the index.php file, which is the entry point for all requests entering your application. This directory also houses your assets such as images, JavaScript, and CSS.
- The resources directory contains your views as well as your raw, un-compiled assets such as LESS, SASS, or JavaScript. This directory also houses all of your language files.
- The routes directory contains all of the route definitions for your application. By default, three route files are included with Laravel: web.php, api.php, and console.php.
- The storage directory contains your compiled Blade templates, file based sessions, file caches, and other files generated by the framework. This directory is segregated into app, framework, and logs directories. The app directory may be used to store any files generated by your application. The framework directory is used to store framework generated files and caches. Finally, the logs directory contains your application’s log files.
- The tests directory contains your automated tests. An example PHPUnit is provided out of the box. Each test class should be suffixed with the word Test. You may run your tests using the phpunit or php vendor/bin/phpunit commands.
- The vendor directory contains your Composer dependencies.
One of the important files in laravel is the .env file, also known as the environment file. My local env file looks like so:
The environment file defines all the important attributes of the project. It also features environment-specific dependencies that we do not want to checkin to the codebase. (all the stuff you want to keep out of git) Attributes that you will find include:
- The database connection
- The filesystem provider
- The log level
- Etc..
All configuration files for a laravel application are located in the config directory. All of the configuration files are array values that will be used by default if the .env file is not present or if the configuration value is not present.
Previous Step: Introduction
Next Step: Creating the Database Tables using Migrations