laravel-best-practices

Applies Laravel PHP best practices when writing, reviewing, or refactoring backend code.

Updated Jun 24, 2026
One-click install
npx skills add https://github.com/stacktracelabs/laravel-vue-starter-kit --skill laravel-best-practices-stacktracelabs
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/stacktracelabs/laravel-vue-starter-kit/tree/main/.agents/skills/laravel-best-practices
Command: npx skills add https://github.com/stacktracelabs/laravel-vue-starter-kit --skill laravel-best-practices-stacktracelabs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Laravel offers multiple valid approaches for nearly every task, and inconsistent or suboptimal patterns lead to N+1 queries, security gaps, queue misconfigurations, and unmaintainable controllers. This Skill provides a prioritized, opinionated rule set so AI agents and developers write Laravel code that follows framework conventions and avoids common production pitfalls. ## Core Features & Use Cases - 19 Rule Categories: Covers database performance, advanced queries, security, caching, Eloquent, validation, configuration, testing, queues, routing, HTTP client, events, mail, error handling, scheduling, architecture, migrations, collections, Blade, and code style. - Incorrect vs. Correct Examples: Each rule shows concrete anti-patterns alongside the recommended implementation with runnable PHP code. - Consistency-First Guidance: Instructs agents to check sibling files for existing project patterns before applying any default rule. - Use Case: When asked to add a new API endpoint, the Skill directs the agent to use Form Request validation, implicit route model binding, thin controllers with action classes, eager loading, and proper authorization. ## Quick Start Ask the agent to review your Laravel controller or write a new Eloquent query, and it will apply the relevant best-practice rules automatically.

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 Eloquent?▼

Use eager loading with the with() method to load relationships upfront instead of lazy loading inside loops. Enable Model::preventLazyLoading() in development to catch violations, and use withCount() instead of loading collections just to count them.

What are Laravel best practices for controller code?▼

Keep controller methods under 10 lines by extracting business logic into invokable action or service classes. Type-hint Form Requests for automatic validation, use implicit route model binding, and use Route::resource() or apiResource() for RESTful endpoints.

How should I configure Laravel queue jobs to avoid duplicates?▼

Set retry_after greater than the job timeout, implement ShouldBeUnique or ShouldBeUniqueUntilProcessing, and always define a failed() handler. Use exponential backoff arrays like [1, 5, 10] and RateLimited middleware for external API calls.

Does this skill work with any Laravel version?▼

The rules target modern Laravel conventions, but some APIs like Cache::flexible() or LazilyRefreshDatabase depend on the installed version. The skill instructs agents to verify exact syntax using the search-docs tool against the project's Laravel version.

When should I use chunk() versus cursor() in Laravel?▼

Use cursor() for memory-efficient read-only iteration over large datasets, loading one record at a time. Use chunk() or chunkById() when modifying records during iteration, since chunkById() avoids offset shifts caused by updated rows.