Fork me on GitHub


Disclaimer: Majority of the assets, design and format of this site is borrowed (forked might be the more better term) from the original PHP : The Right Way site. The original contributors is given all the credits due to them.

This site serves as a guide for those who is using Laravel Framework by Taylor Otwell and its contributors. Laravel : Best Practices aims to put together all the resources and best practices in using the Laravel Framework.

Laravel Framework is not strict on how and where you define your classes as long as it could be loaded by Composer. This is a double-sided blade – it’s beneficial for advanced developers, but coud be confusing for beginners and for those who is trying to reverse engineer an existing codebase. The ability to place anything, anywhere is good. But there are times some methods is way better than the others, and that is what we are after. This site tried to collect all the best practices, tools and methodologies, so that it could serve a guide for beginners and existing developers alike.

This is a living document and will continue to be updated with more helpful information and examples as they become available.


Laravel: The Best Practices is currently available in the following languages. Please contribute to the project so that it could support multiple languages.

How to Contribute

Help make this website the best resource for new PHP programmers! Contribute on GitHub

Spread the Word!

Laravel Best Practices has web banner images you can use on your website. Show your support, and let new PHP developers know where to find good information!

See Banner Images

Download the Android Application

Get it in Google Play

Back to Top

Getting Started

The Ecosystem

At the very minimum, you need to know how to use Git and Composer. Though not required, it is better that you have an account on as it is where all the code and its’ dependencies are hosted.

For local development, you’ll need to have at least Vagrant and VirtualBox installed. This is used by Homestead (a special vagrant box made for running Laravel apps). Although you can use the traditional WAMP/MAMP/XAMPP stack, those are not officially supported, thus you might have hard time down the road.

Pure “Laravel-way” frontend development might be a daunting one as it got has a long chain of technologies. At the very top of the chain is Elixir, which is basically an API for GulpJS, which in turn requires npm which is basically a package manager for NodeJS.

CSS is managed either through Sass or LESS, while JavaScript is through CoffeeScript. You can write ES6/ES7 code since Elixir also supports BabelJS. While NodeJS dependencies are then made available to browsers through Browserify.

For the backend stack, at the very least, you need a web server like Nginx, a php interpreter like PHP-FPM and a database like MySQL. Other optional stack components are Memcached, Redis and Beanstalkd.

While you are not required to understand them all at once, it is advantagous that you are at least familiar with these and do some reading about what they are and where they are being used. This will save you tons of confusion when reading the documentation and references in the future.

Use the Current Stable Version (5.4)

If you are getting started with Laravel, start with the current stable release of Laravel 5.4. Laravel has added powerful new features over the last few years. If you are looking for a function or its usage, the documentation on the website will have the answer.


Laravel is not only using Vagrant as the official development environment but also has its own base box called “Homestead”. You can use Homestead to start developing with Laravel without the hassle of setting up your local environment for Laravel.

The instructions and usage of homestead can be found in the Official Documentation.

Build your own Homestead

Homestead comes with pre-installed software. If you want to customize the installed software, you will need to have access to the scripts that is used to build Homestead itself. This project is called “Settler”. You can check the source code of that project to have a better understanding of how Homestead was built, and probably add your own scripts as well.

Back to Top

Code Style Guide

The Laravel framework itself doesn’t impose standards on how you should name your variables or where to put files. As long as it can be loaded by Composer, it will technically run inside the application. However, developers are encouraged to study and follow the following PSR standards:

Back to Top

Framework Highlights

Programming Paradigms

Design Patterns

There are several design patterns that power Laravel. Phill Sparks has a wonderful presentation about this.

How Laravel Works?

Christopher Pitt has an impressive explanation of the inner workings of Laravel, you can check it out in

Eloquent ORM

The most popular feature of Laravel is its rockstar ORM called Eloquent. It’s the easiest way to use an ORM in your application. You can read more about Eloquent in the official documentation.

Command Line Interface

Laravel comes with its own command line interface called Artisan. It basically uses the Symfony Console component as its foundation. Laracasts has good tutorials on understanding how commands works and how to make your own.


Laravel’s cool error page is something that it is known for, thanks to the Whoops library which powers the error page you see whenever there is an error.

Note that the Whoops library has been removed from Laravel 5.

Back to Top

Dependency Management

Laravel is not built from scratch. It is built on top of several frameworks and libraries. You can see the list of other libraries it uses here. It is also powered by Illuminate components. All of these components are combined by making sure each of them can be treated and written as a composer Composer library. These libraries are hosted in public repositories.

Composer and Packagist

By default, Packagist is used as a package repository and GitHub to download the files itself. But you can define your own repositories by setting up your own Satis mirror of packages. Although you can use any class or even plain php functions inside Laravel (as long as it can be autoloaded). This is not a recommended practice. Make your own Composer library for each application specific set of classes and include it as a dependency in the composer.json file.

Laravel Package Archivists

These are the sites where you can find Laravel Packages:

Back to Top

Coding Practices

The Basics

Laravel has tons of features which might be overwhelming at first.

Here are some articles and resources that may be useful to get on the same page with Laravel.

Date and Time

Although PHP has a class named DateTime to help you when reading, writing, comparing or calculating with date and time. It is recommended that you use the Carbon library for dealing with dates.

Design Patterns

It is easy to mess up your Laravel application if you don’t have any sort of pattern to follow. The following design patterns are recommended for those who are building an application with Laravel or want to refactor their existing projects:

Working with UTF-8

Laravel uses the patchwork/utf8 for most of its UT8-related stuff. It is required that all developers understands the following concepts:

Back to Top

Database Conventions

Eloquent can support multiple Database for a reason - Don’t limit yourself to MySQL.

Use MongoDB for records that have attributes that vary a lot. For example, in an inventory system, an office supplies product might have a different set of fields compared to vehicle and auto supplies.

Use ElasticSearch for high volume data searching and indexing.

Use Neo4J for applications that require complex relationships between models. For example a multi-level networking application, social network site and similar apps.

Table and field naming

Table and field names MUST be lowercase and use Snake Case.

Table names should use the plural form of the actual real life object it is storing. Like for example, the table name for blog posts should be posts not post.

Primary keys should be named “id” in the table names. While the foreign key it represents in other table should be on singularform_id. (e.g. table: post, primary key: id, foreign key: post_id )

Changing tables, index or inserting sample data.

DON’T create tables or index directly via PHPMyAdmin or console. Use database migration to create table, add/alter any fields, and commit those to Git repository.

DON’T directly pass the database export (sql files) to your colleagues in order to share your database changes. Let them run the migration files you committed to the repository.

DON’T insert fake values directly into the database for testing purposes. Create Seeder files to populate your database.

Choose right database for the job at hand.

Eloquent can support multiple databases for a reason - don’t limit yourself to MySQL.

Use MongoDB for records that have attributes that vary a lot. For example, in an inventory system, an office supplies product might have a different set of fields compared to vehicle and auto supplies.

Use ElasticSearch for high volume data searching and indexing. It is also useful on systems that requires sharding of data across multiple machines which is very huge to fit in a single replica.

Use Neo4J for applications that requires complex relationships between models. For example a multi-level networking application, social network site and alike. Although you can do the same in MySQL, the amount of joins when you go beyond 2-level parent-child relationships will be unbearable in any production environment.

Back to Top


Always make sure your application key is set. This is the APP_KEY variable in your .env file. You can generate one via

php artisan key:generate

Always give your application a name. That is, instead of using the default App root namespace given by Laravel install, set it to what the application is all about. This can be set via

php artisan app:name YourAppName

This makes your controllers/models etc resolve into YourAppName\Controllers and YourAppName\Models.

Use .env files to store any secure information and retrieve it via getenv function. These should be no instance on which you will put it inside models/controllers and commit it to Git.

Back to Top


From the Source

People to Follow


PHP PaaS Providers


Illuminate components which can be found in

are the smaller parts that make up the Laravel Framework. Several other open-source libraries are used by Laravel, which can be seen in its composer.json file

Other Useful Resources


Youtube Channels


Back to Top


User Groups


Back to Top