<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Pembelian extends Model
{
use SoftDeletes;
protected $guarded = [];
protected $primaryKey = "no_pembelian";
public $incrementing = false;
public function supplier()
{
return $this->belongsTo(Supplier::class,'kd_supplier')->withTrashed();
}
public function userPemohon()
{
return $this->belongsTo(User::class,'pemohon')->withTrashed();
}
public function userPenyetuju()
{
return $this->belongsTo(User::class,'penyetuju')->withTrashed();
}
public function detail()
{
return $this->hasMany(DetailPembelian::class,'no_pembelian');
}
public function getJumlahAttribute()
{
$jumlah = 0;
foreach ($this->detail as $e) {
$jumlah += $e->jumlah;
}
return $jumlah;
}
public function delete(){
$this->detail()->delete();
parent::delete();
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]