<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Invoice extends Model
{
use SoftDeletes;
protected $guarded = [];
public function prepared()
{
return $this->belongsTo(User::class,'prepared_id')->withTrashed();
}
public function detail()
{
return $this->hasMany(DetailInvoice::class)->withTrashed();
}
public function getTotalAttribute()
{
$total = 0;
foreach ($this->detail as $d) {
$total += $d->qty * $d->harga;
}
return $total;
}
public function delete(){
$this->detail()->delete();
parent::delete();
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]