laravel-patterns

Implements Laravel architecture patterns for controllers, services, Eloquent models, queues, and API resources.

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill laravel-patterns-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-patterns
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/laravel-patterns
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill laravel-patterns-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Structuring a Laravel application for production often leads to fat controllers, inconsistent API responses, N+1 query problems, and tangled domain logic. This Skill provides proven architectural patterns so your Laravel apps stay maintainable, testable, and scalable as they grow. ## Core Features & Use Cases - Layered Architecture: Keep controllers thin by delegating orchestration to services and single-purpose actions, with form requests handling validation and DTO conversion. - Eloquent Best Practices: Typed models with casts, query scopes, eager loading to avoid N+1 queries, transactions for multi-step writes, and conventional migrations. - API & Background Work: Consistent API resource responses with pagination metadata, scoped route-model binding for multi-tenant safety, plus queues, events, and caching strategies. - Use Case: When building a multi-tenant orders API, use scoped route bindings to prevent cross-account access, wrap order creation in a transaction, and return a paginated OrderResource collection. ## Quick Start Ask the agent to scaffold a Laravel orders endpoint using thin controllers, a CreateOrderAction, form request validation, and a paginated API resource response.

Frequently Asked Questions about laravel-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Laravel application with controllers and services?▼

Keep controllers thin by delegating orchestration to services and single-purpose actions. Controllers receive validated form requests, call an action like CreateOrderAction, and return an API resource, keeping HTTP, domain, and data layers clearly separated.

How to avoid N+1 queries in Laravel Eloquent?▼

Use eager loading with the with() method to load relationships upfront, such as Order::with(['customer', 'items.product'])->paginate(25). This fetches related models in a constant number of queries instead of one query per parent record.

What is scoped route model binding in Laravel?▼

Scoped bindings enforce that a nested child model belongs to its parent in the URL, using Route::scopeBindings(). This prevents cross-tenant access, so /accounts/{account}/projects/{project} only resolves projects owned by that account.

Should I use form requests or validate in the controller?▼

Use form requests to keep validation rules, authorization checks, and DTO transformation out of controllers. A StoreOrderRequest can define rules(), authorize() against a policy, and expose a toDto() method for clean handoff to actions.

When should Laravel work be moved to queues?▼

Move IO-heavy or slow work like report generation, exports, emails, and webhook delivery into queued jobs. Prefer idempotent job handlers with retries and backoff so failures can be safely retried without duplicating side effects.