laravel-patterns

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill laravel-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/laravel-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill laravel-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Structuring a Laravel application for long-term maintainability is hard: controllers grow fat, queries cause N+1 problems, and cross-tenant data leaks happen through careless route binding. This Skill provides production-grade Laravel architecture patterns covering routing, Eloquent, services, queues, caching, and API responses. ## Core Features & Use Cases - Layered Architecture: Keep controllers thin by delegating to services and single-purpose action classes, with form requests handling validation and DTO conversion. - Eloquent Best Practices: Typed casts, query scopes, eager loading to avoid N+1 queries, transactions, global scopes, and soft deletes. - Secure Routing: Scoped route-model bindings and explicit model bindings to prevent cross-tenant access in nested resources. - Use Case: When building a multi-tenant Laravel API, apply scoped bindings for nested routes like /accounts/{account}/projects/{project}, wrap multi-step writes in DB transactions, and return consistent paginated responses via API resources. ## Quick Start Ask the assistant to scaffold a Laravel orders API with thin controllers, an action class, form request validation, scoped route bindings, and a paginated 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 service classes and single-purpose logic to action classes. Controllers receive validated form requests, call an action, and return an API resource response.

How to prevent 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 per record.

What is scoped route model binding in Laravel?

Scoped bindings enforce parent-child relationships in nested routes using Route::scopeBindings(). A child model like {project} is only resolved if it belongs to the parent {account}, preventing cross-tenant data access.

How do I validate request data in Laravel APIs?

Create a form request class extending FormRequest with authorize() and rules() methods. Add a toDto() method to transform validated input into a data transfer object passed to your action or service layer.

When should I use queues and events in Laravel?

Use queued jobs for slow work like reports, exports, and webhooks, and emit domain events for side effects such as emails and analytics. Handlers should be idempotent with retries and backoff configured.

Should I use a global scope or a query scope for the same filter?

Use either a global scope or a named scope for the same filter, not both, unless you intend layered behavior. Global scopes apply default filtering automatically, while named scopes like scopeOwnedBy are applied explicitly in queries.