31 lines
No EOL
735 B
PHP
31 lines
No EOL
735 B
PHP
<?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);
|
|
}
|
|
} |