laravel-patterns

Apply Laravel architecture patterns for routing, controllers, Eloquent models, and services.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill laravel-patterns-xxih
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-patterns
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/laravel-patterns
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill laravel-patterns-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reduce architectural drift and scattered business logic in Laravel applications by providing consistent, production-grade patterns for routing, controllers, Eloquent models, services, queues, events, caching, API resources, migrations, and validation so teams can deliver scalable, maintainable systems.

Core Features & Use Cases

  • Clear boundaries: Enforce controller -> service/action -> model separation to keep controllers thin and business logic testable.
  • Routing & authorization: Use route model binding, scopeBindings, and explicit bindings to prevent cross-tenant access and keep routes predictable.
  • Eloquent best practices: Typed casts, value objects, scopes, query objects, preloading to avoid N+1, and soft deletes/global scopes for default filters.
  • Resilience & background work: Offload IO-heavy tasks to queues with retry/ backoff strategies and design idempotent job handlers.
  • API consistency: Standardize JSON responses with resources and pagination, and centralize configuration in config files for environment-specific behavior.
  • Use case: Design a multi-tenant API that enforces scoped access, caches expensive reads with tag-based invalidation, and processes exports via queued jobs.

Quick Start

Create a scoped API route, implement a thin controller that delegates to a typed service action which returns a paginated API resource and invalidates related caches on model events.

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 to keep controllers thin and business logic testable?▼

Standardize Laravel API responses by using API resources with pagination. This approach ensures consistent JSON outputs, centralizes environment-specific configuration in config files, and maintains predictable data structures across endpoints.

How does route model binding prevent cross-tenant access in Laravel APIs?▼

Route model binding prevents cross-tenant access by applying scopeBindings and explicit route bindings. This enforces predictable, scoped access in multi-tenant Laravel APIs, ensuring users only query records they are authorized to view.

What's the best way to cache expensive Laravel reads and invalidate them on data changes?▼

The best way to cache expensive Laravel reads is using tag-based cache invalidation triggered on model events. This pattern ensures cached data remains consistent with database records without manual cache clearing workflows.

How do I offload IO-heavy tasks in Laravel without blocking the main request?▼

Offload IO-heavy Laravel tasks to queues using jobs with retry and backoff strategies. Design idempotent job handlers to process background work like data exports safely, ensuring multi-step updates remain transactionally safe.

Does this Laravel architecture pattern support transactionally safe multi-step updates?▼

Yes, this Laravel architecture pattern supports transactionally safe multi-step updates. It provides production-grade workflows for Eloquent models, services, and validation that maintain data integrity during complex operations.