ldc-boutique-cnc-sable/app/Dto/DiscountProductDto.php
Jérémy Munsch 44ffc4d34e
feat(DiscountProductDto): add picture property and update fromModel method
feat(ProductDragAndDropComponent): enhance product display with picture and improve layout
2026-10-28 10:02:43 +01:00

52 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Dto;
use App\Models\Product;
use Illuminate\Contracts\Support\Arrayable;
/**
* @implements Arrayable<string, string>
*/
final readonly class DiscountProductDto implements \JsonSerializable, Arrayable
{
public function __construct(
public string $id,
public string $name,
public ?string $picture,
) {
}
public static function fromModel(Product $product): self
{
return new self(
id: (string) $product->id,
name: (string) $product->name,
picture: $product->picture,
);
}
/**
* @return array{id: string, name: string}
*/
#[\Override]
public function toArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'picture' => $this->picture,
];
}
/**
* @return array{id: string, name: string}
*/
#[\Override]
public function jsonSerialize(): array
{
return $this->toArray();
}
}