Skip to content

Commit

Permalink
update price
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 28, 2023
1 parent 075953d commit 82c2232
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/Fields/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public function __construct(string $label, string $currency = null)
$this->currency = $currency ?: Bazar::getCurrency();

parent::__construct($label, sprintf('price_%s', strtolower($this->currency)));

$this->asNumber();

$this->field->min(0);

$this->field->format(function (Request $request, Model $model, mixed $value): ?string {
return is_null($value) ? null : Str::currency($value, $this->currency);
});
}

/**
Expand All @@ -36,18 +44,4 @@ public function currency(string $value): static

return $this;
}

/**
* {@inheritdoc}
*/
public function resolveFormat(Request $request, Model $model): mixed
{
if (is_null($this->formatResolver)) {
$this->formatResolver = function (Request $request, Model $model, mixed $value): ?string {
return is_null($value) ? null : Str::currency($value, $this->currency);
};
}

return parent::resolveFormat($request, $model);
}
}

0 comments on commit 82c2232

Please sign in to comment.