mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 11:24:03 +00:00
feat: extract currency from the formatted string
This commit is contained in:
parent
fa337d29b4
commit
93aeb2c300
4 changed files with 57 additions and 3 deletions
|
|
@ -174,6 +174,10 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
|||
/** Create a Money instance from a formatted string. */
|
||||
public static function fromFormatted(string $formatted, Currency|string $currency = null, mixed ...$overrides): self
|
||||
{
|
||||
$currency = isset($currency)
|
||||
? currency($currency)
|
||||
: PriceFormatter::extractCurrency($formatted);
|
||||
|
||||
$decimal = PriceFormatter::resolve($formatted, currency($currency), variadic_array($overrides));
|
||||
|
||||
return static::fromDecimal($decimal, currency($currency));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue