Skip to content

Validated DTOTyped, validated data for Laravel

Define the data shape once, validate it with the rules you already know, and pass typed objects between requests, jobs, commands, and services.

Validated DTO for Laravel

Shipping manifest

  1. 01 / Input
    [
      'name'  => 'Taylor',
      'email' => '[email protected]',
      'age'   => '36',
    ]
  2. 02 / Rules and casts
    // rules()
    'name'  => ['required', 'string'],
    'email' => ['required', 'email'],
    'age'   => ['required', 'integer'],
    
    // casts()
    'age'   => new IntegerCast(),
  3. 03 / DTO
    $dto = UserDTO::fromArray($input);
    
    $dto->name;  // 'Taylor'
    $dto->age;   // 36