create image upload endpoint create product creation endpoint create get product categories endpoint
37 lines
760 B
PHP
37 lines
760 B
PHP
<?php
|
|
|
|
namespace App\Data;
|
|
|
|
use App\Contracts\OutputDataTransferObject;
|
|
use App\Models\ProductCategory;
|
|
|
|
final readonly class ProductCategoryDTO implements OutputDataTransferObject
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $name,
|
|
public string $slug,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'slug' => $this->slug,
|
|
];
|
|
}
|
|
|
|
public static function fromModel(ProductCategory $category): self
|
|
{
|
|
return new self(
|
|
id: $category->id,
|
|
name: $category->name,
|
|
slug: $category->slug,
|
|
);
|
|
}
|
|
}
|