Getting Started with Laravel: Part I

DZone's Guide to

Getting Started with Laravel: Part I

This is part 1 of a series of tutorials on how to get started with one of the most popular PHP frameworks out there, Laravel. Read on to find out how you can make use of this framework for your own projects!

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 application's unit tests in this folder.