*/ class MoneyCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, mixed $value, array $attributes): Money { $currency = $this->getCurrency(); if (! is_numeric($value)) { throw new \InvalidArgumentException('The given value is not numeric.'); } if (! is_string($value) && ! is_int($value)) { throw new \InvalidArgumentException('The given value must be a string or integer.'); } return new Money($value, $currency); } /** @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if ($value instanceof Money) { return $value->getAmount(); } throw new \InvalidArgumentException('The given value is not an instance of Money.'); } protected function getCurrency(): Currency { return resolve(Currency::class); } }