whatisgithub

What is laravel-best-practices?

alexeymezenin/laravel-best-practices — explained in plain English

Analysis updated 2026-06-24

12,276Audience · developerComplexity · 1/5Setup · easy

In one sentence

A curated guide to writing clean, maintainable Laravel PHP code, with side-by-side bad vs. good examples for patterns like service classes, Eloquent, and naming conventions.

Mindmap

mindmap
  root((laravel-best-practices))
    What it does
      Side-by-side examples
      Bad vs good patterns
      20+ languages
    Key Principles
      Single responsibility
      Fat models thin controllers
      Service classes
      Eloquent over raw SQL
    Performance
      N+1 problem
      Chunking large data
    Code Style
      Naming conventions
      Config files
      No HTML in PHP
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Follow proven patterns to structure a Laravel app so other developers can read and maintain it easily

USE CASE 2

Avoid the N+1 query performance trap when loading related data in Laravel pages

USE CASE 3

Move validation, business logic, and database queries into the right classes as experienced Laravel developers expect

What is it built with?

PHPLaravel

How does it compare?

alexeymezenin/laravel-best-practicesatomiks/tippyjsbpampuch/pdfmake
Stars12,27612,27712,275
LanguageJavaScriptJavaScript
Setup difficultyeasyeasyeasy
Complexity1/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

So what is it?

This repository is a guide to writing clean, well-organized code in Laravel, a popular PHP framework used to build web applications. Rather than teaching Laravel from scratch, it collects a set of opinionated rules and patterns that experienced Laravel developers follow to keep projects readable and easy to maintain over time. Each section in the guide focuses on one principle, usually illustrated with two code examples side by side: one labeled "Bad" showing a common mistake, and one labeled "Good" showing the recommended approach. The principles covered include keeping each class or method focused on a single task, putting database query logic inside the data model instead of the controller, moving validation rules into their own classes, and placing business logic in dedicated service classes rather than scattering it throughout the application. Other sections address more specific habits: avoiding repeated code, using Laravel's built-in data querying tool called Eloquent instead of raw SQL, and preventing a common performance trap known as the N+1 problem (where a page accidentally fires dozens of database queries by loading related data one piece at a time). There are also sections on chunking large data sets to avoid memory limits, using descriptive method and variable names, keeping HTML and CSS out of server-side template files, storing configuration values in dedicated files rather than hardcoding strings in code, and following Laravel's own naming conventions so that any developer familiar with the framework can read any Laravel project without extra context. The guide is available in over 20 languages, including Chinese, Japanese, Russian, Portuguese, Arabic, and several others, reflecting how widely read it is across the global developer community.

Copy-paste prompts

Prompt 1
How do I refactor this Laravel controller to move business logic into a service class, following the laravel-best-practices guide?
Prompt 2
Show me how to fix an N+1 query problem in my Laravel app using Eloquent eager loading as recommended in alexeymezenin/laravel-best-practices
Prompt 3
How should I use Laravel Form Requests to move validation out of my controller per the laravel-best-practices guide?
Prompt 4
What naming conventions should my Laravel models, controllers, and methods follow according to alexeymezenin/laravel-best-practices?

Frequently asked questions

What is laravel-best-practices?

A curated guide to writing clean, maintainable Laravel PHP code, with side-by-side bad vs. good examples for patterns like service classes, Eloquent, and naming conventions.

How hard is laravel-best-practices to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is laravel-best-practices for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.