buckets/app/Models/Traits/HasAmount.php

31 lines
735 B
PHP
Raw Normal View History

2025-12-31 01:48:13 +01:00
<?php
namespace App\Models\Traits;
trait HasAmount
{
/**
* Get amount in currency units (stored as minor units/cents).
*/
public function getAmountCurrencyAttribute(): float
{
return $this->amount / 100;
}
/**
* Set amount from currency units (stores as minor units/cents).
*/
public function setAmountCurrencyAttribute($value): void
{
$this->attributes['amount'] = round($value * 100);
}
/**
* Format amount for display with proper currency formatting.
* This can be extended later to support different currencies.
*/
public function getFormattedAmountAttribute(): string
{
return number_format($this->amount / 100, 2);
}
}