Skip to content

Attributes Overview

Complete reference of all 50+ attributes available in SimpleDTO.

SimpleDTO provides 50+ attributes organized into categories:

  • Validation Attributes (30+) - Data validation
  • Conditional Attributes (18) - Visibility control
  • Cast Attributes (1) - Type casting
  • Mapping Attributes (2) - Property mapping
  • Computed Attributes (1) - Calculated properties
  • Lazy Attributes (1) - Deferred evaluation
  • Hidden Attributes (1) - Always hidden

See Validation Attributes for complete list of 30+ validation attributes.

Most Common:

  • #[Required] - Property must be present
  • #[Email] - Valid email address
  • #[Min(int $value)] - Minimum value/length
  • #[Max(int $value)] - Maximum value/length
  • #[Between(int $min, int $max)] - Value between range
  • #[In(array $values)] - Value in array
  • #[Unique(string $table, string $column)] - Unique in database
  • #[Exists(string $table, string $column)] - Exists in database

See Conditional Attributes for complete list of 18 conditional attributes.

Most Common:

  • #[WhenAuth] - Show when authenticated (Laravel)
  • #[WhenCan(string $permission)] - Show when user has permission (Laravel)
  • #[WhenRole(string $role)] - Show when user has role (Laravel)
  • #[WhenValue(string $property, mixed $value)] - Show when property equals value
  • #[WhenNull(string $property)] - Show when property is null

See Casting Attributes for complete list.

  • #[Cast(string $castClass)] - Cast property to specific type

See Mapping Attributes for complete list.

  • #[MapFrom(string $source)] - Map from different input key
  • #[MapTo(string $target)] - Map to different output key
  • #[Computed] - Mark method as computed property
  • #[Lazy] - Defer property evaluation
  • #[Hidden] - Always hide property

You can combine multiple attributes on a single property:

class UserDTO extends SimpleDTO
{
public function __construct(
// Validation + Mapping
#[Required, Email, MapFrom('user_email')]
public readonly string $email,
// Validation + Cast
#[Required, Cast(DateTimeCast::class)]
public readonly Carbon $createdAt,
// Conditional + Cast
#[WhenAuth, Cast(EncryptedCast::class)]
public readonly ?string $ssn = null,
// Multiple Conditionals
#[WhenAuth, WhenRole('admin')]
public readonly ?array $adminData = null,
) {}
}

Data Validation:

Visibility Control:

Data Transformation:

  • 1 cast attribute (20+ cast classes)
  • 2 mapping attributes
  • See Casting and Mapping

Computed Values:

  • 1 computed attribute
  • 1 lazy attribute

Framework-Agnostic:

  • All validation attributes
  • Core conditional attributes (9)
  • Cast, mapping, computed, lazy, hidden

Laravel-Specific:

  • WhenAuth, WhenGuest, WhenCan, WhenRole

Symfony-Specific:

  • WhenGranted, WhenSymfonyRole
// ✅ Good - specific attribute
#[WhenAuth]
public readonly ?string $email;
// ❌ Bad - generic callback
#[WhenCallback(fn() => auth()->check())]
public readonly ?string $email;
// ✅ Good - logical combination
#[Required, Email, MapFrom('user_email')]
public readonly string $email;
// ❌ Bad - conflicting attributes
#[Required, Nullable]
public readonly ?string $email;
// ✅ Good - with type hint
#[Cast(DateTimeCast::class)]
public readonly Carbon $date;
// ❌ Bad - no type hint
#[Cast(DateTimeCast::class)]
public readonly $date;