nova-money-field
nova-money-field copied to clipboard
dynamic currency symbol
Is it possible to get currency symbol from other field value?
in the DB I am storing monetary values in two fields: amount
(in minor units) and currency
(as a lowercase currency symbol 'eur','usd','gbp') it would be nice if formatting would depend on currency
field value.
You can use $this->currency
in Nova resource then.
Works for index & detail view however not for form.
I'm using Money::make('Amount', strtoupper($this->currency))->storedInMinorUnits(),
and getting this error:
"message": "Cannot find currency ",
"exception": "Money\\Exception\\UnknownCurrencyException",
"file": "/Users/XXX/XXX/XXX/vendor/moneyphp/money/src/Currencies/AggregateCurrencies.php",
"line": 60,
$this->currency ?? 'USD'
?
no luck, same error, however $this->currency ? $this->currency : 'USD'
worked
when i \Log::info $this->currency
in fields
function, it logs twice: first exact value from the model and second time empty string
, have no clue why.
[2018-12-24 22:41:19] local.INFO: EUR
[2018-12-24 22:41:20] local.INFO:
[2018-12-24 22:41:25] local.INFO:
[2018-12-24 22:41:25] local.INFO:
[2018-12-24 22:41:25] local.INFO: EUR
[2018-12-24 22:41:25] local.INFO: USD
[2018-12-24 22:41:25] local.INFO:
I had a similar problem as @R00118189 , using $this->currency
would work perfectly when in list view, but fail when in detail view BUT ONLY if I also outputted the related table. Using $this->currency ? $this->currency : 'USD'
worked.
I should point out the error I got was:
Argument 1 passed to Vyuldashev\NovaMoneyField\Money::subUnits() must be of the type string, null given, called in /home/eugene/code/bas/vendor/vyuldashev/nova-money-field/src/Money.php on line 29 {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0):