laravel-patterns

Structure Laravel 12 backend code with service layers and thin controllers.

Updated Jul 19, 2025
One-click install
npx skills add https://github.com/omanjaya/attendancedev --skill laravel-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-patterns
Source: https://github.com/omanjaya/attendancedev/tree/main/.claude/skills/laravel-patterns
Command: npx skills add https://github.com/omanjaya/attendancedev --skill laravel-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive guidance for building clean, maintainable Laravel 12 applications by applying modern PHP and Laravel conventions such as a service layer, thin controllers, form requests, DTOs, Enums, and robust model patterns. It helps teams reduce complexity and increase testability.

Core Features & Use Cases

  • Service Layer Pattern: Move business logic out of controllers into dedicated services.
  • Thin Controllers: Controllers handle HTTP concerns and delegate to services.
  • Form Requests & Validation: Centralized validation rules and custom messages.
  • Eloquent & Patterns: Repositories, DTOs, Enums, and clean model designs.
  • Use Case: When building an HR system, implement services for employee management, while keeping controllers slim and easily testable.

Quick Start

Create a new EmployeeController with a thin controller that delegates to EmployeeService to handle creation.

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 a service layer pattern?

A service layer pattern moves business logic from controllers into dedicated service classes. Create services to handle core operations like employee management, then inject them into thin controllers that only manage HTTP requests and responses. This separation improves testability and maintainability across your Laravel application.

What's the best way to validate form input in Laravel 12?

Use Form Requests to centralize validation rules and custom messages separate from controllers. Form Requests handle authorization and validation before data reaches your controller action, keeping controllers thin and validation logic reusable across your application.

How do I use DTOs and Enums to structure data flow in Laravel?

Data Transfer Objects and Enums provide typed data contracts between controllers, services, and models. DTOs shape data moving through your application, while Enums represent fixed sets of values. Together they enforce type safety and make data flow explicit and testable.

Can I apply these Laravel patterns to an existing application?

Yes. Start by extracting business logic from controllers into services, then introduce Form Requests for validation and DTOs for data flow. Apply these patterns incrementally to new features or during refactoring. The patterns work with existing Eloquent models and relationships.

What are the key differences between thin controllers and fat controllers in Laravel?

Thin controllers delegate business logic to services and only handle HTTP concerns like routing, validation dispatch, and responses. Fat controllers mix HTTP handling with business logic, making them harder to test and reuse. Service layer patterns enable thin controllers by providing a clear place for business logic.

How do Eloquent models and relationships fit into this architecture?

Models define database structure and relationships; services orchestrate business operations using those models. Keep models focused on data representation and relationships while services handle complex workflows, transactions, and cross-model operations that keep your code clean and testable.