From 041375b92e885fbaed8de0ea2dd2a5e5baa42711 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Wed, 4 Dec 2024 17:33:31 +0100 Subject: [PATCH] Add support for money cast on model --- src/Forms/Components/MoneyInput.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Forms/Components/MoneyInput.php b/src/Forms/Components/MoneyInput.php index e65cb45..55e664c 100644 --- a/src/Forms/Components/MoneyInput.php +++ b/src/Forms/Components/MoneyInput.php @@ -22,10 +22,14 @@ protected function setUp(): void $this->prepare(); - $this->formatStateUsing(function (MoneyInput $component, $state): ?string { + $this->formatStateUsing(function (MoneyInput $component, $record, $state): ?string { $this->prepare(); + if ($state instanceof Money) { + $state = $state->getAmount(); + } + $currency = $component->getCurrency(); $locale = $component->getLocale(); @@ -39,7 +43,7 @@ protected function setUp(): void return MoneyFormatter::formatAsDecimal((int) $state, $currency, $locale, $this->getDecimals()); }); - $this->dehydrateStateUsing(function (MoneyInput $component, $state): ?string { + $this->dehydrateStateUsing(function (MoneyInput $component, $record, $state): ?string { $currency = $component->getCurrency(); if ($state instanceof Money) {