Paulund
2016-10-11 #laravel

Getting Started With Laravel

Laravel is one of the most popular, if not THE most popular PHP framework and after using Laravel and comparing it with the likes of Zend and Symfony it's easy to see why, over the courses of multiple tutorials we're going to go over some of the best features of Laravel.

Laravel has so many features and helpful classes that you can quickly and easily build any application or API with Laravel.

Installing Laravel

There are multiple ways you can install Laravel, the easiest way you can install Laravel is by using composer.


composer global require "laravel/installer"

Once Laravel is installed it will have a command of laravel new which you can use to create your new project.


laravel new created-new-project

This will add a fresh Laravel installation into the directory you're in.

Directory Structure

Once Laravel is installed it will create the structure of the application.

  • App
  • Bootstrap
  • Config
  • Database
  • Public
  • Resources
  • Routes
  • Storage
  • Tests
  • Vendor

App

The app folder is used to home the classes for your application such as commandline class or controller classes. Laravel comes pre-installed with controllers you can use in almost all of your applications such as the Authentication controllers to manage login, reset password and register forms.

Bootstrap

Bootstrap folder is used to house objects such as instantiating the Laravel application and defining the autoload functionality.

Config

Config folder is used to house the settings for your application. Some of these application settings can be overridden from the environment settings you define in the root of the application.

Database

The database folder is used to store the factories, migration and seed files for your application.

Public

The public folder is where you documentroot should be pointing to. This is the folder that holds your index.php and is what will be loaded when visitors navigate to your application. This folder is where you will store all your compiled CSS and JS files used in the application.

Resources

Laravel development uses the MVC development method and will store the view of the MVC inside the resources folder. Laravel also chooses Sass and VueJS for your frontend development, you should use the resources folder to store the un-compiled Sass and VueJS files.

Routes

This is a new folder in Laravel 5.3, before this will sit in the app/http folder, it is here that you will include all the routes for your application. This is split up into API routes, Console routes and Web routes allowing you to better organise the routes.

Storage

The storage folder is used for any files you need to store in the application such as user uploaded files. This is also where you will store cache and log files for your application. You need to make sure that the storage folder is writable by your web server or Laravel will not work correctly.

Tests

As the name suggests you will store your applications unit tests in this folder. View this to learn more about test driven development.

Vendor

The vendor folder is where your third party dependencies will be stored after they have been imported using Composer.

Application Key

To setup your Laravel application you need to generate a unique application, this key is used as the salt for your users sessions and other encrypted data. To generate an application key you can use the Artisan command

php artisan key:generate

Homestead

Laravel comes with a local environment setup called Homestead which is a simple Vagrant virtual machine providing you with the perfect setup for your Laravel applications. First you need to make sure that Vagrant is setup on your machine, so you will need to install VirtualBox and Vagrant. Homestead is a pre-built Vagrant box which can be easily installed by

vagrant box add laravel/homestead

Then you can install the Homestead installation files by cloning the repository.


git clone https://github.com/laravel/homestead.git Homestead

Once the repository is cloned run the command


bash init.sh

Will create the Homestead configuration file where you can edit the settings of your virtual machine. Homestead