laravel-best-practices

Applies Laravel best-practice rules when writing, reviewing, or refactoring PHP application code.

1|Updated Aug 29, 2026
One-click install
npx skills add https://github.com/IzzatFirdaus/task-enterprise-api --skill laravel-best-practices-izzatfirdaus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/IzzatFirdaus/task-enterprise-api/tree/main/.github/skills/laravel-best-practices
Command: npx skills add https://github.com/IzzatFirdaus/task-enterprise-api --skill laravel-best-practices-izzatfirdaus

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 patterns, N+1 query bugs, security gaps, and unmaintainable controllers. This Skill provides an indexed rule set covering the full Laravel stack so code changes follow proven conventions instead of ad-hoc decisions. ## Core Features & Use Cases - Indexed Rule Library: Twenty rule files covering Eloquent, migrations, routing, validation, security, caching, queues, scheduling, mail, events, HTTP client, error handling, Blade, collections, configuration, and architecture. - Consistency-First Guidance: Instructs checking existing codebase patterns before applying any rule, so changes match the project's established conventions. - Code Review Support: Maps common concerns (N+1 queries, mass assignment, missing authorization, unsafe retries) to concrete before/after code examples. - Use Case: When refactoring a controller that lazy-loads relationships, the Skill directs you to the db-performance rules for eager loading with with(), constrained selects, and preventLazyLoading() in development. ## Quick Start Ask the assistant 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?▼

Eager load relationships with `with()` before iterating, and constrain the eager load to only needed columns while keeping the keys Eloquent uses for matching. Enable `Model::preventLazyLoading()` in non-production environments to surface violations during development.

How should I structure Laravel controllers and routes?▼

Organize controllers around one resource using standard actions like index, show, store, update, and destroy, and use implicit route model binding. Extract substantial business logic into action or service classes, and consider modeling custom verbs as separate resource controllers.

When should I use a form request instead of inline validation in Laravel?▼

Use a form request when validation or authorization is substantial, reused, or clearer outside the controller; its `authorize()` method can also enforce access. Inline `$request->validate()` remains appropriate for small, endpoint-specific rule sets.

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 it with validated input via `validated()` or `safe()` and explicit authorization through policies or gates.

How do I configure Laravel queue retries and timeouts correctly?▼

Set `retry_after` longer than the worker's `--timeout` so jobs are not reserved twice, and use `$backoff` arrays for progressively longer delays on transient failures. Make important jobs idempotent, since workers can stop after side effects but before acknowledging a job.

When should I avoid global scopes in Eloquent?▼

Global scopes silently modify every query on a model, which complicates debugging and hides rows from admin panels, reports, and jobs. Prefer explicit local scopes and reserve global scopes for universal constraints like soft deletes or multi-tenancy.