laravel-best-practices

Applies Laravel best-practice rules when writing, reviewing, or refactoring PHP code.

Updated Jul 18, 2026
One-click install
npx skills add https://github.com/daviddatuX25/Serbizyu-2.0 --skill laravel-best-practices-daviddatux25
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/daviddatuX25/Serbizyu-2.0/tree/main/.cursor/skills/laravel-best-practices
Command: npx skills add https://github.com/daviddatuX25/Serbizyu-2.0 --skill laravel-best-practices-daviddatux25

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Laravel offers multiple valid ways to solve the same problem, which leads to inconsistent patterns, N+1 query bugs, security gaps, and unmaintainable controllers. This Skill provides an indexed rulebook of Laravel best practices so code is written and reviewed against concrete, verifiable standards. ## Core Features & Use Cases - Rule Index by Concern: Twenty rule files covering database performance, Eloquent, security, validation, routing, migrations, queues, caching, HTTP client, error handling, events, mail, scheduling, collections, Blade, config, testing, style, and architecture. - Consistency-First Guidance: Instructs checking existing codebase patterns before applying any rule, so new code matches established conventions instead of introducing a second approach. - Incorrect/Correct Examples: Each rule shows concrete wrong and right PHP code, covering issues like N+1 queries, missing authorization, unvalidated input, and queue misconfiguration. - Use Case: While refactoring a controller that loads posts with their authors, the Skill directs you to the db-performance rules, where you apply eager loading with with() and constrained column selection to eliminate the N+1 problem. ## Quick Start Ask the AI to review your Laravel controller, model, or migration against the Laravel best practices rules and fix any violations it finds.

Frequently Asked Questions about laravel-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 query problems in Laravel?▼

Use eager loading with `with()` to load relationships upfront instead of lazy loading inside loops. You can also enable `Model::preventLazyLoading()` in development to throw an exception whenever a relationship is accessed without being eager-loaded.

How should I structure validation in Laravel controllers?▼

Extract validation into dedicated Form Request classes and type-hint them in controller methods, which triggers validation and authorization automatically. Always use `$request->validated()` for mass operations instead of `$request->all()`.

What is the best way to handle Laravel queue job retries?▼

Set `retry_after` greater than the job's `timeout` so workers do not re-dispatch running jobs, and use exponential backoff via the `$backoff` property. Implement `failed()` for explicit error handling and `ShouldBeUnique` to prevent duplicate processing.

Does this Laravel guidance apply to any framework version?▼

The rules target modern Laravel conventions, but version-sensitive APIs should be verified against the installed framework version. The Skill instructs checking the installed framework or documentation when an API's behavior may differ between versions.

When should I not follow these Laravel best practices?▼

When the existing codebase already follows a different established pattern, consistency takes priority over the rule. Deviations are justified only for correctness or security defects, and they should be called out explicitly.