Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

laravel-best-practices — Claude Code skill: setup and rules

Indexes Laravel backend conventions for models, migrations, queues, and queries. It enforces existing codebase patterns before introducing new abstractions.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add laravel/boost --skill laravel-best-practices -a claude-code
Open on GitHub

What laravel-best-practices does

This skill guides AI agents through writing and refactoring Laravel backend code. Its primary directive is consistency. Before editing, the agent must inspect neighboring controllers, models, and tests to match existing project conventions. Introducing a second pattern when one already works is strictly discouraged.

The skill organizes rules across separate topical files. These cover database performance, Eloquent scopes, validation, authorization, and queue configuration. To verify version-specific framework APIs, the workflow checks search-docs or the installed vendor files directly.

Testing logic is offloaded to a separate testing-best-practices skill. Keeping queries out of Blade templates prevents hidden N+1 issues during serialization and rendering.

What it helps with

  • eliminate hidden N+1 queries across Eloquent relationships and resources
  • refactor controllers and service classes to match existing application structure
  • configure queue retries and batching according to framework conventions
  • review backend PHP changes against Laravel security and routing practices

Example prompts for the agent

  • Review OrderController for N+1 queries using laravel-best-practices rules
  • Generate a migration and an Eloquent model following laravel-best-practices
  • Refactor ProcessPayment job with proper retry configuration and error handling

How to install laravel-best-practices

1Skills CLI (Vercel)

npx skills add laravel/boost --skill laravel-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/laravel-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/laravel-best-practices/

Similar

two-factor-authentication-best-practices better-auth Walks an agent through adding two-factor auth to a Better Auth app: TOTP, codes by email or SMS, backup codes, trusted devices. Claude Code CX Codex Cursor +1 34,200installs architect-review sickn33 Turns the agent into an architecture reviewer: it weighs design decisions, names the risks and tradeoffs, and asks for a validation plan. Claude Code CX Codex Cursor +1 1,300installs langgraph sickn33 A skill for building production-grade agents with deliberate structure. Design graph topology, manage state, add cycles and branches, persist progress via checkpoints, and loop humans back into decisions. Claude Code CX Codex Cursor +1 1,300installs wp-plugin-development WordPress This skill guides WordPress plugin work, from project structure and hooks to admin settings, security checks and release packaging. Claude Code CX Codex Cursor +1 7,900installs firecrawl-build-scrape firecrawl This skill guides integration of Firecrawl /scrape into product code for single-page extraction. It applies when an app has a known URL and needs markdown, HTML, or metadata. Claude Code CX Codex Cursor +1 61,600installs dart-resolve-package-conflicts dart-lang Skill for resolving Dart package version conflicts when pub get fails. Teaches how to audit dependencies, update packages within constraints, and surgically remove entries from the lockfile. Claude Code CX Codex Cursor +1 18,600installs mcp-builder official anthropics This skill walks through building an MCP server in TypeScript or Python, from reading the protocol spec to writing tests and evaluation questions. Claude Code Claude.ai 130,949installs google-agents-cli-adk-code official Google A reference skill for building ADK agents with tools, callbacks, state, and workflows. Use it when an agent project needs concrete API patterns or code examples. Claude Code CX Codex Cursor +1 511,400installs

Questions about laravel-best-practices

How to install laravel-best-practices in Claude Code?

Run npx skills add laravel/boost --skill laravel-best-practices -a claude-code. You can also place the file directly at ~/.claude/skills/laravel-best-practices/SKILL.md.

What does the laravel-best-practices skill do?

It provides an index of architectural and coding rules for Laravel applications. The skill instructs the agent to check database queries, routing, validation, and queue jobs while keeping existing codebase patterns intact.

How does the skill handle conflicts with existing code patterns?

Existing application patterns always win. The skill explicitly forbids adding a secondary pattern if the project already follows an established approach, deviating only for security or correctness bugs.

Source text

SKILL.md · MIT
---
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
---

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

© laravel · MIT · laravel/boost

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor