# Introduction

You can easily cast your DTO properties by defining a casts method in your DTO:

```php
protected function casts(): array
{
    return [
        'name' => new StringCast(),
        'age'  => new IntegerCast(),
        'created_at' => new CarbonImmutableCast(),
    ];
}
```

Alternatively, for simpler cases, you can use the `Cast` attribute:

```php
use WendellAdriel\ValidatedDTO\Attributes\Cast;
use WendellAdriel\ValidatedDTO\Concerns\EmptyCasts;

class UserDTO extends ValidatedDTO
{
    use EmptyCasts;

    public string $name;

    public string $email;

    #[Cast(BooleanCast::class)]
    public bool $active;

    #[Cast(IntegerCast::class)]
    public ?int $age;

    #[Cast(type: ArrayCast::class, param: FloatCast::class)]
    public ?array $grades;
}
```

If you're using attributes to define the casting of your properties or if you don't have any casting for the properties, you can use the `EmptyCasts` trait to avoid having to define the `casts()` method.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wendell-adriel.gitbook.io/laravel-validated-dto/type-casting/introduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
