laravel-dtos

Formalize Laravel DTO patterns with Spatie Laravel Data for type-safe contracts.

1|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-dtos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-dtos
Source: https://github.com/nextplus896/durra-alaseel/tree/main/.github/skills/claude-laravel/laravel-dtos
Command: npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-dtos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a standardized approach to defining Data Transfer Objects (DTOs) in Laravel projects using Spatie Laravel Data, offering type safety, clear contracts between layers, and reusable patterns for API requests, responses, and domain data.

Core Features & Use Cases

  • Type-safe DTOs with constructor-promoted properties for clear, self-documenting data objects.
  • Nested DTOs, validation hooks, and transformation patterns for complex data flows.
  • Static factories and test factories to simplify testing and data generation.
  • Guidelines for transformers, data mapping, and repository/controller usage across controllers and services.

Quick Start

Define a simple DTO class using promoted properties, then map an incoming API request into the DTO with a static from* method, and validate the data in tests.

Frequently Asked Questions about laravel-dtos

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

FAQPage Schema
How do I build type-safe Laravel DTOs for API requests and responses?

Type-safe Laravel DTOs are built using Spatie Laravel Data with constructor-promoted properties and static from* methods, enforcing clear data contracts between API layers. This approach provides self-documenting data objects for requests and responses.

What is the best way to structure nested DTOs in Laravel applications?

Nested DTOs in Laravel are structured using Spatie Laravel Data to handle complex data flows across controllers and services. This pattern applies transformation hooks and static factories to map nested domain data cleanly across application boundaries.

How do Laravel DTOs handle data validation and test factory generation?

Laravel DTOs handle data validation through built-in hooks and simplify test factory generation using dedicated test factories. This provides reusable patterns for generating test data and verifying data integrity across service boundaries.

Can I use Laravel DTOs for model casts and service boundaries?

Laravel DTOs support optional model casts and define clear service boundaries using Spatie Laravel Data. This enforces type safety across domain data, guiding structure and usage within controllers, actions, and transformers.

Does Spatie Laravel Data work with custom transformers and data mapping?

Spatie Laravel Data works with custom transformers and data mapping to format API responses. It provides guidelines for repository and controller usage, ensuring consistent data transformation across complex Laravel workflows.

When do I need DTOs in Laravel instead of passing arrays directly?

DTOs in Laravel are needed when passing arrays directly creates unclear contracts between application layers. Using Spatie Laravel Data enforces type safety, validates data structures, and provides self-documenting boundaries for complex domain data.