osb/app/Models/Payment.php

48 lines
796 B
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model
{
protected $table = 'ab_payment';
protected $dates = ['date_payment'];
protected $with = ['account.country.currency','items'];
2018-05-20 12:53:14 +00:00
protected $appends = [
'date_paid',
'total',
];
protected $visible = [
'date_paid',
'id',
'total',
];
public function account()
{
return $this->belongsTo(\App\User::class);
}
public function items()
{
return $this->hasMany(PaymentItem::class);
}
public function getDatePaidAttribute()
2018-05-20 12:53:14 +00:00
{
return $this->date_payment->format('Y-m-d');
}
public function getTotalAttribute()
{
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total_amt);
}
public function currency()
{
return $this->account->country->currency;
}
2018-05-20 12:53:14 +00:00
}