Refactor models.

This commit is contained in:
James Cole
2025-09-14 09:00:01 +02:00
parent 935453796e
commit 9d9483e20f
46 changed files with 688 additions and 676 deletions

View File

@@ -37,6 +37,7 @@ class CurrencyExchangeRate extends Model
use ReturnsIntegerIdTrait;
use ReturnsIntegerUserIdTrait;
use SoftDeletes;
protected $fillable = ['user_id', 'from_currency_id', 'to_currency_id', 'date', 'date_tz', 'rate'];
public function fromCurrency(): BelongsTo
@@ -54,34 +55,6 @@ class CurrencyExchangeRate extends Model
return $this->belongsTo(User::class);
}
protected function fromCurrencyId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function rate(): Attribute
{
return Attribute::make(
get: static fn ($value) => (string) $value,
);
}
protected function toCurrencyId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int) $value,
);
}
protected function userRate(): Attribute
{
return Attribute::make(
get: static fn ($value) => (string) $value,
);
}
protected function casts(): array
{
return [
@@ -96,4 +69,32 @@ class CurrencyExchangeRate extends Model
'user_rate' => 'string',
];
}
protected function fromCurrencyId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
protected function rate(): Attribute
{
return Attribute::make(
get: static fn($value) => (string)$value,
);
}
protected function toCurrencyId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
);
}
protected function userRate(): Attribute
{
return Attribute::make(
get: static fn($value) => (string)$value,
);
}
}