'boolean', 'symbol_first' => 'boolean', 'rate' => CurrencyRateCast::class, ]; protected $appends = ['live_rate']; protected function liveRate(): Attribute { return Attribute::get(static function (mixed $value, array $attributes): ?float { $baseCurrency = CurrencyAccessor::getDefaultCurrency(); $targetCurrency = $attributes['code']; if ($baseCurrency === $targetCurrency) { return 1; } $exchangeRate = Forex::getCachedExchangeRate($baseCurrency, $targetCurrency); return $exchangeRate ?? null; }); } public function defaultCurrency(): HasOne { return $this->hasOne(CompanyDefault::class, 'currency_code', 'code'); } public function accounts(): HasMany { return $this->hasMany(Account::class, 'currency_code', 'code'); } public function accountHistories(): HasMany { return $this->hasMany(AccountHistory::class, 'currency_code', 'code'); } protected static function newFactory(): Factory { return CurrencyFactory::new(); } }