Files
dailydish/app/Dtos/TagDto.php
T

45 lines
907 B
PHP
Raw Normal View History

2026-08-09 20:15:40 +03:00
<?php
namespace App\Dtos;
class TagDto
{
public ?int $id = null;
public ?string $name = null;
public ?string $slug = null;
public ?int $createdAt = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->name = $data['name'] ?? null;
$dto->slug = $data['slug'] ?? null;
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'createdAt' => $this->createdAt,
];
}
}