class MyModel extends Model
{
protected $fillable = ['name', 'metadata'];
protected $casts = [
'metadata' => AttributesDTO::class,
];
}
class AttributesDTO extends ValidatedDTO
{
public int $age;
public string $doc;
protected function rules(): array
{
return [
'age' => ['required', 'integer'],
'doc' => ['required', 'string'],
];
}
protected function defaults(): array
{
return [];
}
protected function casts(): array
{
return [
'age' => new IntegerCast(),
'doc' => new StringCast(),
];
}
}