ekart/backend/app/Data/ProductImageDTO.php
kusowl 920666c201 feature: add index endpoint for products
- implement DTO for product and modify productImageDTO.
- add products resources and collection.
2026-02-27 18:16:02 +05:30

37 lines
792 B
PHP

<?php
namespace App\Data;
use App\Contracts\OutputDataTransferObject;
use App\Models\ProductImage;
final readonly class ProductImageDTO implements OutputDataTransferObject
{
public function __construct(
public ?int $id = null,
public ?string $path = null,
public ?int $productId = null,
) {}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'id' => $this->id,
'path' => $this->path,
'productId' => $this->productId,
];
}
public static function fromModel(ProductImage $productImage): self
{
return new self(
$productImage->id,
$productImage->path,
$productImage->product_id
);
}
}