laravel-dto

Generate immutable PHP DTO classes with static factory methods for Laravel.

Updated May 11, 2026
One-click install
npx skills add https://github.com/irizqi/agent-skills --skill laravel-dto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-dto
Source: https://github.com/irizqi/agent-skills/tree/main/skills/laravel-dto
Command: npx skills add https://github.com/irizqi/agent-skills --skill laravel-dto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the maintenance and reliability issues caused by passing loose associative arrays between Laravel application layers, ensuring data integrity and type safety.

Core Features & Use Cases

  • Type-Safe Data Structures: Enforces strict typing for input and output data using immutable PHP classes.
  • Standardized Mapping: Provides a consistent pattern for static factory methods to transform raw arrays or models into structured objects.
  • Use Case: Use this skill when refactoring service layers or repository responses to replace unstructured arrays with predictable, testable DTOs that improve IDE autocompletion and reduce runtime errors.

Quick Start

Use the laravel-dto skill to generate a new DTO class for the UserProfile response including a factory method for mapping from an Eloquent model.

Frequently Asked Questions about laravel-dto

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

FAQPage Schema
How do I replace loose associative arrays with type-safe DTOs in Laravel?

To replace loose arrays with type-safe DTOs in Laravel, you implement immutable PHP classes with static factory methods. This pattern standardizes data mapping from raw arrays or Eloquent models, ensuring strict typing between controllers, services, and repositories.

Why should I use Data Transfer Objects instead of arrays in Laravel service layers?

Data Transfer Objects solve maintenance and reliability issues caused by passing unstructured arrays across Laravel layers. Using immutable DTOs enforces type safety, improves IDE autocompletion, reduces runtime errors, and ensures predictable data handling in complex backend architectures.

What is the best way to map Eloquent model data to a DTO in Laravel?

The best way to map Eloquent model data to a DTO is using static factory methods within immutable PHP classes. This provides a consistent pattern for transforming raw data into structured objects, ensuring standardized mapping and type-safe communication across repositories and services.

Does refactoring Laravel controllers to use DTOs improve application testability?

Refactoring Laravel controllers to use DTOs significantly improves testability by standardizing data handling with type-safe, immutable PHP classes. Predictable data structures replace loose arrays, making it easier to mock responses and verify structured data passing between layers.

When do I need Data Transfer Objects in a Laravel backend architecture?

You need Data Transfer Objects in a Laravel backend architecture when passing data between controllers, services, and repositories becomes difficult to maintain. DTOs are essential for complex applications requiring structured data handling, strict type safety, and reliable communication.

Can I use immutable PHP classes for Laravel repository responses?

Yes, you can use immutable PHP classes for Laravel repository responses by implementing them as Data Transfer Objects. Static factory methods transform repository data into structured objects, ensuring type-safe communication and predictable data mapping back to the service layer.