Laravel dto

From event4u-app/agent-config · View interactive version

Laravel dto is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when creating a Laravel/PHP DTO with the SimpleDto base class and attribute mapping. For DTOs in other stacks, use the stack-native skill (TypeScript, Python, Rust, Go).

How to use this skill

Skill file

laravel-dto

When to use

Use this skill when creating a new DTO for data transfer between layers (DB ↔ PHP, API ↔ Service, etc.).

Procedure: Create a DTO

  1. Read the project's DTO docs — check agents/reference/docs/dto.md (if it exists) for project-specific conventions.
  2. Check the base class — search for the DTO base class in the project (e.g., SimpleDto, LiteDto, or a custom base).

Check composer.json for DTO-related packages.

  1. Check existing DTOs — look at neighboring DTOs in the same directory to match the style.
  2. Understand the model — if the DTO maps to a Model, read the model's properties and DB columns.

DTO conventions

Base class

Property mapping

Type casting

Validation

Model linkage

Structure

<?php

declare(strict_types=1);

namespace App\DTO;

use Vendor\DataHelpers\SimpleDto;
use Vendor\DataHelpers\SimpleDto\Attributes\HasModel;
use Vendor\DataHelpers\SimpleDto\Attributes\Map;

#[HasModel(MyModel::class)]
final class MyModelDto extends SimpleDto
{
    public function __construct(
        #[Map('id_column')]
        public readonly ?int $id = null,

        #[Map('name_column')]
        public readonly string $name = '',

        #[Map('amount_column')]
        public readonly float $amount = 0.0,
    ) {}
}

Project detection

The DTO pattern varies by project:

Read agents/reference/docs/dto.md for full details (if it exists).

Some projects use plain readonly classes, others have custom base classes.

Always check composer.json for DTO-related packages before choosing the approach.

Rules

Output format

  1. DTO class per the project's convention, with typed constructor-promoted properties
  2. Static factory method(s) for construction from common sources

Gotcha

Do NOT

Auto-trigger keywords

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.