'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 bills(): HasMany { return $this->hasMany(Bill::class, 'currency_code', 'code'); } public function clients(): HasMany { return $this->hasMany(Client::class, 'currency_code', 'code'); } public function estimates(): HasMany { return $this->hasMany(Estimate::class, 'currency_code', 'code'); } public function invoices(): HasMany { return $this->hasMany(Invoice::class, 'currency_code', 'code'); } public function recurringInvoices(): HasMany { return $this->hasMany(RecurringInvoice::class, 'currency_code', 'code'); } public function vendors(): HasMany { return $this->hasMany(Vendor::class, 'currency_code', 'code'); } protected static function newFactory(): Factory { return CurrencyFactory::new(); } }