跳到正文
cccskills
免费在 GitHub 公开

laravel-dto

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).

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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.
  3. Check existing DTOs — look at neighboring DTOs in the same directory to match the style.
  4. Understand the model — if the DTO maps to a Model, read the model's properties and DB columns.

DTO conventions

Base class

  • Use the project's standard DTO base class (typically SimpleDto or LiteDto).
  • Never create plain PHP classes for DTOs that map to models — always extend the base class.

Property mapping

  • Use #[Map('db_column')] attributes to map between DB column names and PHP properties.
  • PHP properties: camelCase, English names.
  • DB columns: snake_case, may be German (legacy) — match what's in the database.

Type casting

  • Use typed properties (int, string, float, bool, Carbon, etc.).
  • The base class handles casting from DB strings to PHP types automatically.

Validation

  • Use validation attributes where appropriate: #[Length(50)], #[Email], #[Decimal(10,2)], #[Unsigned].
  • Add #[ConvertEmptyToNull] at class level if empty strings should become null.

Model linkage

  • Add #[HasModel(ModelClass::class)] on the DTO.
  • Add #[HasDto(DtoClass::class)] and DtoMappingTrait on the Model (if not already present).

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)]
class MyModelDto extends SimpleDto
{
    #[Map('id_column')]
    public ?int $id = null;

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

    #[Map('amount_column')]
    public float $amount = 0.0;
}

Project detection

The DTO pattern varies by project:

  • Projects with a DTO package: Use the package's base class with attribute mapping. Read agents/reference/docs/dto.md for full details (if it exists).
  • Projects without a DTO package: Check existing DTOs for the local pattern. Some projects use plain readonly classes, others have custom base classes.

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

Rules

  • Match existing patterns — if the project already has DTOs, follow their style.
  • Do NOT create DTOs for trivial data — if a simple array or typed parameter suffices, don't over-engineer.
  • Use Math helper for any calculated properties — never raw PHP arithmetic.
  • declare(strict_types=1) in every new file.

Output format

  1. DTO class extending SimpleDto with typed properties
  2. Static factory method(s) for construction from common sources

Gotcha

  • DTOs must extend SimpleDto — don't create plain PHP classes as DTOs.
  • The model forgets to add the model linkage ($modelClass) when the DTO maps to an Eloquent model.
  • Attribute names in the DTO must match the database column names (snake_case), not the PHP property names.

Do NOT

  • Do NOT add business logic to DTOs — they are data containers only.
  • Do NOT use arrays when a DTO can provide type safety.
  • Do NOT skip validation when creating DTOs from external input.

Auto-trigger keywords

  • DTO
  • data transfer object
  • SimpleDto
  • attribute mapping

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Use when reviewing UI for accessibility — WCAG 2.2 AA, keyboard nav, focus, ARIA, contrast, screen-reader semantics — even on 'is this a11y-OK?' or 'mach das barrierefrei'.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

Use when defining or auditing the activation event — aha-moment selection, retention correlation, falsifiable definition. Triggers on 'what is our aha moment', 'redefine activation'.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

Use when capturing an architectural decision — file naming, next ADR number, Status / Context / Decision / Consequences, index regen; fires even without saying 'ADR'.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

Adversarial critique — devil's advocate, stress-test, honest teardown ('poke holes', 'be brutal', 'was hältst du davon'); explicit request only. Routine code or design review → code-review.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

Use when reading, creating, or updating agent documentation, module docs, roadmaps, or AGENTS.md. Understands the full .augment/, agents/, and copilot-instructions structure.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

Use for an adversarial red-team / blue-team / auditor review of an AI agent's CONFIG + behaviour (rules, skills, MCP, hooks, permissions) — attack-chain → defensive-gap list, not a code audit.

中文简介正在准备中。当前显示原文说明。

event4u-app/agent-config132026年10月22日 更新

查看 event4u-app 的全部技能

报告此技能的问题