laravel-best-practices

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

Updated Aug 5, 2026
One-click install
npx skills add https://github.com/rizalord/livecode-ptbeon --skill laravel-best-practices-rizalord
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/rizalord/livecode-ptbeon/tree/main/src/backend/.grok/skills/laravel-best-practices
Command: npx skills add https://github.com/rizalord/livecode-ptbeon --skill laravel-best-practices-rizalord

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 Eloquent, migrations, validation, routing, security, caching, queues, testing, and more, each with incorrect/correct code examples. - Consistency-First Guidance: Instructs checking existing codebase patterns before applying any rule, avoiding the introduction of competing conventions. - Use Case: When refactoring a controller that lazy-loads relationships, the Skill maps the change to the db-performance and eloquent rule files, guiding eager loading with with(), column selection, and preventLazyLoading() setup. ## Quick Start Review my Laravel controller and model code for N+1 query problems and apply the relevant best practice rules.

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. Enable `Model::preventLazyLoading()` in your AppServiceProvider during development to catch violations, and use `withCount()` when you only need relation counts.

What are Laravel best practices for validation?▼

Extract validation into dedicated Form Request classes and type-hint them in controller methods for automatic validation. Always use `$request->validated()` for mass operations instead of `$request->all()`, and prefer array notation for rules in new code.

Should I use whereHas or whereIn for Laravel relationship queries?▼

Prefer `whereIn()` with a `select('id')` subquery over `whereHas()` for filtering by related models. `whereHas()` emits a correlated EXISTS subquery that re-executes per row, while `whereIn()` lets the database use an index lookup.

Does this Laravel guidance apply to older framework versions?▼

Some rules use newer APIs like `defer()`, `Context`, and `Cache::flexible()` that require recent Laravel versions. The Skill instructs verifying version-sensitive APIs against the installed framework before applying them.

When should I use queues versus defer() in Laravel?▼

Use queued jobs when work must survive process crashes or needs retry logic, such as external API calls. Use `defer()` for lightweight fire-and-forget tasks like logging or analytics that run after the HTTP response is sent.