laravel-12-best-practices

Software engineering best practices for Laravel 12.x, covering architecture, Eloquent, testing, security, and the new starter kits.

16 stars

Best use case

laravel-12-best-practices is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Software engineering best practices for Laravel 12.x, covering architecture, Eloquent, testing, security, and the new starter kits.

Teams using laravel-12-best-practices should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/laravel-12-best-practices/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/laravel-12-best-practices/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/laravel-12-best-practices/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How laravel-12-best-practices Compares

Feature / Agentlaravel-12-best-practicesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Software engineering best practices for Laravel 12.x, covering architecture, Eloquent, testing, security, and the new starter kits.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Laravel 12.x Best Practices

This skill outlines the recommended software engineering practices for developing applications with Laravel 12.x. It incorporates modern PHP 8.2+ features, the latest Laravel 12 enhancements (such as the new starter kits and UUIDv7 defaults), and industry-standard architecture patterns.

## When to Use

- **New or existing Laravel 12.x apps:** Apply to greenfield or existing apps, with or without the official starter kits, including setups that still adopt Inertia 2.0 or UUIDv7 defaults.
- **Architecture decisions:** Apply when choosing between standard MVC and domain-driven structure for complex domains.
- **Quality gates:** Apply when establishing linting, static analysis, and refactoring automation (Pint, PHPStan, Rector).
- **Eloquent & data access:** Apply when designing models, resource transformations, and query strictness to avoid N+1 issues.
- **Testing strategy:** Apply when selecting Pest or PHPUnit and standardizing factories and JSON assertions.
- **Security posture:** Apply when enforcing FormRequest validation, policy authorization, and safe query practices.

## 1. Project Setup & Architecture

### Starter Kits
For new projects, prefer using the official Laravel 12 starter kits which now feature improved defaults:
- **Frontend:** Use the React, Vue, or Livewire starter kits which now integrate **Inertia 2.0**, **TypeScript**, **Shadcn/UI**, and **Tailwind CSS** out of the box.
- **Authentication:** Consider the **WorkOS AuthKit** variant included in starter kits for robust social auth, passkeys, and SSO support if building SaaS or enterprise apps.

### Directory Structure
- **Standard MVC:** Follow the default `app/` structure for small-to-medium applications.
- **Domain Driven Design (DDD):** For complex applications, organize code by domain (e.g., `src/Domains/Order`, `src/Domains/User`) rather than by technical layer.
- **Strict Typing:** Enable strict types in all PHP files (`declare(strict_types=1);`).

## 2. Code Quality & Style

- **Linting:** Use **Laravel Pint** (built on top of PHP-CS-Fixer) to enforce the PER Coding Style.
- **Static Analysis:** Maintain a high level of code safety using **PHPStan** (Level 5 minimum recommended).
- **Refactoring:** Utilize the `rector/rector` package to automatically upgrade older PHP syntax to modern PHP 8.2+ standards.

## 3. Eloquent & Database

### Model Practices
- **UUIDs:** Leverage Laravel 12's default support for **UUIDv7** in the `HasUuids` trait for time-sortable unique identifiers.
- **Resources:** Use the new fluent methods for transforming models into API resources:
    ```php
    // Preferred
    return User::find(1)->toResource();
    return User::query()->paginate()->toResourceCollection();
    ```
- **Mass Assignment:** Always use `$fillable` or `$guarded` properties to prevent mass assignment vulnerabilities.
- **Strictness:** Prevent "lazy loading" in development to avoid N+1 query performance issues.
    ```php
    // In AppServiceProvider::boot()
    Model::preventLazyLoading(! $this->app->isProduction());
    ```

### Data Handling
- **Collections:** Use strict collection methods like Arr::sole() when you expect exactly one result.
- **Context:** Use the `Context` facade for handling request-scoped data (logging, tracing) instead of global state.

## 4. Testing

### Frameworks
- **Pest PHP:** Preferred for its expressive syntax and minimal boilerplate.
- **PHPUnit 12:** If using PHPUnit, ensure you are utilizing v12 features supported by Laravel 12.

### Best Practices
- **Factories:** Always use Model Factories for test data generation. Avoid manually inserting rows.
- **Assertions:** Use fluent JSON assertions for API testing:
    ```php
    $response->assertJson(fn (AssertableJson $json) =>
        $json->has('data')
             ->where('data.id', 1)
             ->etc()
    );
    ```
- **Queue Faking:** Utilize the enhanced Queue::fake() assertions to verify job dispatch logic without running the actual background processes.

## 5. Security

- **Validation:** Put all validation logic in FormRequest classes, not Controllers.
- **Authorization:** Use Policies and Gates strictly. Ensure every controller action authorizes the user action (e.g., $this->authorize('update', $post)).
- **Sanitization:** Rely on Blade's {{ }} auto-escaping and Eloquent's parameter binding. Never pass user input directly to raw SQL queries.

## 6. Performance

- **Caching:** Utilize Cache::remember for expensive queries.
- **HTTP Client:** Use the afterResponse() hook in the HTTP client to handle cross-cutting concerns (logging, error mapping) for outgoing API requests.
- **Queues:** Offload heavy tasks (emails, report generation) to the queue system. Monitor queues using Laravel Horizon.

## 7. Dependency Management

- **Updates:** Laravel 12 is a "maintenance release" focusing on stability. Keep dependencies updated regularly using composer update.
- **Breaking Changes:** Be aware that while Laravel 12 has zero breaking changes in the framework code, upstream dependencies (like Carbon 3) may have subtle differences.

Related Skills

lit-best-practices

16
from diegosouzapw/awesome-omni-skill

Lit web components best practices and performance optimization guidelines. Use when writing, reviewing, or refactoring Lit web components. Triggers on tasks involving Lit components, custom elements, shadow DOM, reactive properties, or web component performance.

laravel

16
from diegosouzapw/awesome-omni-skill

Use when implementing or debugging this Laravel v12 app; leverage Laravel Boost MCP (search-docs, artisan, schema, logs, tinker) and follow project conventions.

laravel-vite

16
from diegosouzapw/awesome-omni-skill

Complete Vite bundling for Laravel - assets, HMR, SSR, frameworks, optimization. Use when configuring frontend build pipeline.

laravel-type-bridge-development

16
from diegosouzapw/awesome-omni-skill

Generate TypeScript/JavaScript type artifacts from Laravel PHP definitions — enums, i18n translations, and enum translator composables.

laravel-inertia-isolated-plugin-architect

16
from diegosouzapw/awesome-omni-skill

Create a Laravel plugin with an isolated UI which is provided by Inertia.js and Vue.js which can live on any Laravel host app no matter of the used technology in the frontend.

laravel-expert

16
from diegosouzapw/awesome-omni-skill

Senior Laravel Engineer role for production-grade, maintainable, and idiomatic Laravel solutions. Focuses on clean architecture, security, performance, and modern standards (Laravel 10/11+).

kafka-development-practices

16
from diegosouzapw/awesome-omni-skill

Applies general coding standards and best practices for Kafka development with Scala.

jupyter-notebook-best-practices

16
from diegosouzapw/awesome-omni-skill

Guidelines for structuring and documenting Jupyter notebooks for reproducibility and clarity.

js-ts-best-practices

16
from diegosouzapw/awesome-omni-skill

JavaScript and TypeScript best practices covering naming conventions, control flow, state management, TypeScript patterns (avoid any/enum, prefer type over interface), safety (input validation, assertions, error handling), performance optimization (reduce branching/looping, memoization, defer await, cache property access, storage API caching), and documentation (JSDoc, comment markers). Use when writing JS/TS functions, refactoring code for performance, reviewing code quality, fixing type errors, optimizing loops or conditionals, adding validation, or improving error messages.

golang-best-practices

16
from diegosouzapw/awesome-omni-skill

Comprehensive Go code review meta-skill. Coordinates 5 specialized domain skills. For targeted reviews, use domain-specific skills (concurrency-safety, clean-architecture). For full audits, use this meta-skill.

general-best-practices

16
from diegosouzapw/awesome-omni-skill

General software development best practices covering code quality, testing, security, performance, and maintainability across technology stacks

fastapi-best-practices

16
from diegosouzapw/awesome-omni-skill

FastAPI best practices e convenções baseadas em produção real. Aplicar em todos os projetos FastAPI.