*/ final readonly class DiscountDto implements Arrayable, UrlRoutable { public function __construct( public int $id, public DiscountType $type, public DiscountValue $value, public bool $is_old_price_displayed, public ?Carbon $date_start = null, public ?Carbon $date_end = null, public ?Carbon $created_at = null, public ?Carbon $updated_at = null, ) { } public static function fromModel(Discount $discount): self { return new self( id: $discount->id, type: $discount->type, value: $discount->value, is_old_price_displayed: $discount->is_old_price_displayed, date_start: $discount->date_start, date_end: $discount->date_end, created_at: $discount->created_at, updated_at: $discount->updated_at, ); } #[\Override] public function getRouteKey(): mixed { return $this->id; } #[\Override] public function getRouteKeyName(): string { return 'id'; } #[\Override] public function resolveRouteBinding($value, $field = null): mixed { return null; } #[\Override] public function resolveChildRouteBinding($childType, $value, $field): mixed { return null; } /** * @return array */ #[\Override] public function toArray(): array { return [ 'id' => $this->id, 'type' => $this->type->value(), 'value' => $this->value->value(), 'is_old_price_displayed' => $this->is_old_price_displayed, 'date_start' => $this->date_start, 'date_end' => $this->date_end, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } }