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 Mix, which is basically an API for Webpack, which in turn requires npm which is basically a package manager for NodeJS.

CSS is managed either through Sass or LESS, while JavaScript can be done through Plain JavaScript, ReactJS and the more common frontend framework used with Laravel: VueJS.

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.8)

If you are getting started with Laravel, start with the current stable release of Laravel 5.8. 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

Framework Highlights

Programming Paradigms

As you go through Laravel documentation, you’ll encounter a lot of buzz words such as service provider, dependency injection, IoC container, HTTP Resource and so on.

It is a good idea to get some background of these concepts first before diving into using the framework, so you will be able to make sense why the framework is designed this way.

Service Provider

Generally, a Service is a well-known set of programming interfaces and classes that provide access to some specific application functionality or feature. While a Service Provider Interface is an interface or abstract class that acts as a proxy or an endpoint to the service. So by definition, a Service Provider is a specific implementation of the SPI. The Service Provider contains one or more concrete classes that implement or extends the service type.

Dependency Injection

is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client’s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.

Inversion Of Control

IoC inverts the flow of control as compared to traditional control flow. In IoC, custom-written portions of a computer program receive the flow of control from a generic framework. A software architecture with this design inverts control as compared to traditional procedural programming: in traditional programming, the custom code that expresses the purpose of the program calls into reusable libraries to take care of generic tasks, but with inversion of control, it is the framework that calls into the custom, or task-specific code

Command Bus Pattern

The Command Bus pattern is trying to decouple as much as it can the controller, the framework itself to the domain layer, which should be totally unaware of application’s upper layer. It keeps the user interface logic separated from your models.

SOLID Principle

Domain Driven Design

is an approach to software development for complex needs by connecting the implementation to an evolving model. The premise of domain-driven design is the following:

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.

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

Naming Conventions

The following is the generally accepted naming conventions being used by Laravel Community:

Controller Names

Controller name must start with a noun (in singular form) followed by the word “Controller”.


class ArticleController extends Controller


class ArticlesController extends Controller
class wp_articlesController extends Controller
class Article extends Controller

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


Starter Kits

Youtube Channels


Back to Top


User Groups


Back to Top