laravel-best-practices

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

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

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, N+1 query bugs, security gaps, and unreliable queues. This Skill gives an AI agent a structured, indexed rulebook of Laravel best practices so generated or reviewed code follows framework conventions and avoids common defects. ## Core Features & Use Cases - Indexed Rule Library: Twenty topic-specific rule files covering Eloquent, migrations, validation, routing, security, caching, queues, scheduling, mail, events, HTTP client, Blade, collections, error handling, configuration, architecture, and style. - Consistency-First Guidance: Instructs the agent to match existing project patterns before applying any rule, avoiding the introduction of competing conventions. - Code Review and Refactoring: Maps concerns like N+1 queries, mass assignment, missing authorization, and unsafe retries to concrete rules with correct and incorrect code examples. - Use Case: When asked to add an endpoint that lists a user's orders, the agent reads the routing, validation, and db-performance rule files, then produces a resource controller with route model binding, a form request, and eager-loaded relationships. ## Quick Start Ask the agent to review your Laravel controller or write a new feature, and it will apply the relevant rule files automatically.

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 so Laravel runs one relationship query instead of one per model. You can also enable Model::preventLazyLoading() in AppServiceProvider during development to throw an exception whenever a relationship is lazy loaded.

How should I structure Laravel controllers and routes?▼

Organize controllers around a single resource using the standard actions index, show, create, store, edit, update, and destroy, and register them with Route::resource(). Treat custom verbs like publish as a signal to consider a separate resource controller rather than adding unrelated actions.

What is the difference between Cache::remember() and Cache::flexible() in Laravel?▼

Cache::remember() recomputes the value synchronously when the key expires. Cache::flexible() accepts a fresh and stale period, serving stale data during the stale window while deferring the refresh, which reduces response latency for frequently read keys.

Does Laravel validation also authorize the request?▼

No. Validation only checks the shape and values of input; authorization must be handled separately through policies, gates, or a form request's authorize() method. Authentication alone does not establish permission to perform an action.

Why do my Laravel queued jobs run twice or overlap?▼

Duplicate execution happens when retry_after is shorter than the job timeout, letting another worker reserve the same job. Set retry_after above the longest timeout, keep worker --timeout a few seconds shorter, and make important jobs idempotent.

When should I not edit an existing Laravel migration?▼

Once a migration has run in a shared or production environment, treat it as immutable and create a new migration for changes. Editing the old file makes fresh installations diverge from upgraded ones. Only local, undeployed migrations are safe to edit and rerun.