feat(ProductDragAndDropComponent): enhance product display with picture and improve layout
52 lines
1 KiB
PHP
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();
|
|
}
|
|
}
|