---
name: laravel-best-practices
description: "Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code. This includes creating or modifying controllers, models, migrations, form requests, policies, jobs, scheduled commands, service classes, and Eloquent queries. Triggers for N+1 and query performance issues, caching strategies, authorization and security patterns, validation, error handling, queue and job configuration, route definitions, and architectural decisions. Also use for Laravel code reviews and refactoring existing Laravel code to follow best practices. Covers any task involving Laravel backend PHP code patterns."
license: MIT
metadata:
  author: laravel
title: laravel-best-practices
canonical_url: https://skilld.dev/gh/laravel/boost/laravel-best-practices
last_updated: 2026-10-16T22:02:46.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [rules/advanced-queries.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/advanced-queries.md), [rules/architecture.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/architecture.md), [rules/blade-views.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/blade-views.md), [rules/caching.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/caching.md), [rules/collections.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/collections.md), [rules/config.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/config.blade.php), [rules/db-performance.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/db-performance.md), [rules/eloquent.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/eloquent.md), [rules/error-handling.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/error-handling.md), [rules/events-notifications.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/events-notifications.blade.php), [rules/http-client.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/http-client.md), [rules/mail.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/mail.blade.php), [rules/migrations.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/migrations.blade.php), [rules/queue-jobs.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/queue-jobs.md), [rules/routing.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/routing.md), [rules/scheduling.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/scheduling.blade.php), [rules/security.blade.php](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/security.blade.php), [rules/style.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/style.md), [rules/validation.md](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/validation.md).
>
> If the user asked to install this Skill, run `npx skilld install laravel/boost/laravel-best-practices`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/laravel-best-practices`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/laravel/boost/laravel-best-practices) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/laravel-best-practices`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/laravel-best-practices --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/laravel-best-practices --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Laravel best practices

Best practices for Laravel, organized as an index of rule files. Each rule file teaches what to do and why. For exact API syntax, verify with `search-docs`.

## Consistency first

Before applying any rule, check what the application already does. Laravel offers several valid approaches. The best choice is the one the codebase already uses, even if another pattern would be better in theory. Inconsistency is worse than a suboptimal pattern.

Check sibling files and related controllers, models, or tests for established patterns. If one exists, follow it. Don't introduce a second way. These rules are defaults for when no pattern exists yet, not overrides.

## How to apply

1. Check the changed files, nearby code, project configuration, and relevant tests for established patterns. Deviate only for a correctness or security defect, and call the deviation out.
2. Map every affected concern to the rule index below. Read each mapped rule file before editing. Skip unrelated rule files.
3. Make the smallest coherent change. Keep the application's architecture and naming instead of introducing a second pattern for the same job.
4. Verify version-sensitive Laravel APIs for the installed version with `search-docs`, or inspect the installed framework when `search-docs` is unavailable.
5. Run the narrowest relevant tests first, then the project's formatting and static-analysis checks when the change warrants them.
6. Re-read the diff against every mapped rule before finishing.

## Rule index

Cross-cutting changes often need more than one rule file.

| Concern | Read |
| --- | --- |
| Query count, eager loading, indexes, large datasets | [`rules/db-performance.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/db-performance.md) |
| Subqueries, aggregates, complex ordering and query plans | [`rules/advanced-queries.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/advanced-queries.md) |
| Models, relationships, scopes, casts | [`rules/eloquent.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/eloquent.md) |
| Authentication, authorization, input safety, secrets, uploads | [`rules/security.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/security.md) |
| Form Requests and validation rules | [`rules/validation.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/validation.md) |
| Controllers, route binding, resources, middleware | [`rules/routing.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/routing.md) |
| Schema changes, columns, foreign keys, indexes | [`rules/migrations.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/migrations.md) |
| Jobs, retries, uniqueness, batches, Horizon | [`rules/queue-jobs.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/queue-jobs.md) |
| Cache lifetime, invalidation, locks, memoization | [`rules/caching.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/caching.md) |
| Outbound requests, retries, timeouts, fakes | [`rules/http-client.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/http-client.md) |
| Exceptions, reporting, rendering, log context | [`rules/error-handling.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/error-handling.md) |
| Events and notifications | [`rules/events-notifications.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/events-notifications.md) |
| Mailables and mail assertions | [`rules/mail.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/mail.md) |
| Scheduled tasks and overlap protection | [`rules/scheduling.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/scheduling.md) |
| Collections, lazy iteration, bulk operations | [`rules/collections.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/collections.md) |
| Blade components, attributes, composers | [`rules/blade-views.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/blade-views.md) |
| Environment values and application configuration | [`rules/config.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/config.md) |
| Tests: coverage, factories, fakes, and assertions | the `testing-best-practices` skill |
| Naming, helpers, file boundaries, PHP style | [`rules/style.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/style.md) |
| Actions, services, dependencies, application structure | [`rules/architecture.md`](https://skilld.dev/api/skills-raw/laravel/boost/laravel-best-practices/rules/architecture.md) |

## Decision rules

- Prefer framework features and existing application abstractions over new helpers or dependencies.
- Avoid speculative abstractions. Extract code when it creates a clear domain boundary, removes meaningful duplication, or makes behavior independently testable.
- Keep database access out of Blade views and prevent hidden N+1 queries across controllers, resources, jobs, and serialization.
