laravel-best-practices

Applies Laravel PHP best practices when writing, reviewing, and refactoring application code.

Updated Sep 19, 2026
One-click install
npx skills add https://github.com/idehen-divine/lumished --skill laravel-best-practices-idehen-divine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/idehen-divine/lumished/tree/main/.agents/skills/laravel-best-practices
Command: npx skills add https://github.com/idehen-divine/lumished --skill laravel-best-practices-idehen-divine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Laravel offers multiple valid approaches for the same task, and inconsistent or suboptimal patterns lead to N+1 queries, security gaps, and unmaintainable code. This Skill provides an indexed rule set covering the full Laravel stack so code follows proven conventions. ## 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 changes match the project's established conventions. - Use Case: When refactoring a controller that loads posts with authors, the Skill directs you to the db-performance rules to fix N+1 queries with eager loading and the routing rules to keep controllers thin with Form Requests. ## Quick Start Ask the AI to review your Laravel controller, model, or migration for best practice violations and apply the recommended fixes.

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

Fix N+1 queries in Laravel by eager loading relationships with the with() method before iterating. You can also enable Model::preventLazyLoading() in AppServiceProvider during development to throw exceptions when lazy loading occurs.

What are Laravel best practices for form validation?▼

Laravel validation best practices recommend extracting rules into dedicated Form Request classes and always using validated() instead of request->all() for mass operations. Array notation for rules is preferred in new code, but match the project's existing convention.

How should I structure Laravel controllers and business logic?▼

Keep Laravel controllers thin, aiming for under ten lines per method, by extracting business logic into invokable action or service classes. Use constructor dependency injection and type-hint Form Requests for automatic validation.

Does this skill work with different Laravel versions?▼

The rules note that version-sensitive Laravel APIs should be verified against the installed version using documentation search or by inspecting the installed framework. The guidance prioritizes consistency with the existing codebase over any single rule.

Why does my Laravel queued job run twice?▼

Duplicate job execution happens when the queue retry_after configuration is shorter than the job's timeout, causing the worker to re-dispatch a still-running job. Set retry_after safely greater than the maximum job timeout and consider implementing ShouldBeUnique.

When should I use cache tags in Laravel?▼

Use cache tags in Laravel when you need to invalidate related groups of entries atomically with a single flush call. Tags only work with redis, memcached, and dynamodb drivers, not the file or database cache stores.