laravel-best-practices

Applies Laravel coding rules for controllers, Eloquent, queues, caching, and security during code writing and review.

Updated Aug 25, 2026
One-click install
npx skills add https://github.com/mr-creative-hmh/creative-tasks --skill laravel-best-practices-mr-creative-hmh
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/mr-creative-hmh/creative-tasks/tree/main/.agents/skills/laravel-best-practices
Command: npx skills add https://github.com/mr-creative-hmh/creative-tasks --skill laravel-best-practices-mr-creative-hmh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Laravel offers multiple valid ways to solve the same problem, which leads to inconsistent codebases, hidden N+1 query bugs, security gaps, and performance regressions. This Skill provides an indexed rulebook of Laravel best practices so AI-assisted code generation and review follows proven conventions instead of ad-hoc patterns. ## Core Features & Use Cases - Indexed Rule Library: Twenty topic-specific rule files covering Eloquent, migrations, validation, routing, queues, caching, security, testing, Blade, HTTP client, scheduling, and architecture, each with incorrect/correct code examples. - Consistency-First Guidance: Instructs checking existing codebase patterns before applying any rule, so refactors match the project's established conventions rather than introducing a second approach. - Code Review & Refactoring Support: Maps concerns like N+1 queries, missing authorization, or unqueued notifications to the exact rule file to read before editing. - Use Case: While adding a new endpoint that lists orders with their items, the Skill directs you to eager-load relationships, use a Form Request for validation, authorize via a policy, and keep the controller thin by delegating to an action class. ## Quick Start Ask the AI to review or write Laravel code, for example: review this OrderController for N+1 queries, missing authorization, and validation issues using the Laravel best practices skill.

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

Eager load relationships with with() so related models load in one query instead of one per row. You can also enable Model::preventLazyLoading() in AppServiceProvider during development to throw an exception whenever a relationship is lazy-loaded.

How should I validate request data in Laravel controllers?▼

Extract validation into a dedicated Form Request class and type-hint it in the controller method, which triggers validation and authorization automatically. Always use $request->validated() for mass assignment instead of $request->all().

When should I use queues for Laravel notifications and mail?▼

Notifications and mailables that hit external services like email, SMS, or Slack should implement ShouldQueue so they do not block the HTTP response. When dispatched inside a database transaction, use afterCommit() to avoid processing before the commit.

Does this Laravel guidance apply to older framework versions?▼

Some rules use newer APIs such as defer(), Context, Cache::flexible(), and the #[Scope] attribute, which require recent Laravel versions. The Skill instructs verifying version-sensitive APIs against the installed framework before applying them.

What is the difference between cursor(), lazy(), and chunk() in Laravel?▼

cursor() keeps one model in memory but cannot eager-load relationships. lazy() returns a chunked LazyCollection that supports eager loading, while chunk() and chunkById() process records in batches, with chunkById() safe for updates during iteration.