Add all files
This commit is contained in:
32
app/Models/Credit.php
Normal file
32
app/Models/Credit.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Classes\Price;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Credit extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'currency_code',
|
||||
'amount',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo(Currency::class, 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function formattedAmount(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => new Price(['price' => $this->amount, 'currency' => $this->currency])
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user