laravel-best-practices

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

Updated Aug 29, 2026
One-click install
npx skills add https://github.com/F41541/koperasi-app --skill laravel-best-practices-f41541
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/F41541/koperasi-app/tree/main/.agents/skills/laravel-best-practices
Command: npx skills add https://github.com/F41541/koperasi-app --skill laravel-best-practices-f41541

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 AI agents and developers apply consistent, correct patterns when writing or reviewing Laravel PHP code. ## Core Features & Use Cases - Indexed Rule Files: Twenty topic-specific rule files covering Eloquent, migrations, validation, routing, security, caching, queues, scheduling, mail, HTTP client, error handling, Blade, collections, and architecture. - Consistency-First Guidance: Instructs agents to check existing codebase patterns before applying any rule, avoiding the introduction of competing conventions. - Code Review Support: Maps concerns like N+1 detection, mass assignment, authorization, and query performance to concrete rules with correct and incorrect code examples. - Use Case: When refactoring a controller that lazy-loads relationships, the Skill directs you to the database performance rules for eager loading with with(), constrained selects, and preventLazyLoading() in development. ## Quick Start Ask the agent 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 Eloquent?▼

Eager load relationships with `with()` before iterating over models, and use `withCount()` when only relationship counts are needed. Enable `Model::preventLazyLoading()` in development to throw exceptions when lazy loading occurs.

How to validate request data in Laravel controllers?▼

Use a form request class when validation or authorization is substantial or reused, and inline `$request->validate()` for small endpoint-specific rules. Always pass `validated()` or `safe()` data onward instead of `$request->all()`.

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

`cursor()` runs one query hydrating models individually but cannot eager load. `lazy()` runs chunked queries supporting eager loading. Use `lazyById()` or `chunkById()` when updates during iteration could shift offset-based pagination.

Does Laravel mass assignment protection replace validation?▼

No. `$fillable` controls which attributes `create()` and `update()` may set, but it does not validate values or authorize the operation. Combine mass assignment rules with form request validation and policy-based authorization.

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

Use `defer()` for lightweight post-response work that does not need retries or durability. Use queued jobs when the work requires retries, queue controls, or must survive process failures.