<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Penjualan extends Model
{
use SoftDeletes;
protected $guarded = [];
protected $primaryKey = "no_penjualan";
public $incrementing = false;
public function pelanggan()
{
return $this->belongsTo(Pelanggan::class,'kd_pelanggan')->withTrashed();
}
public function user()
{
return $this->belongsTo(User::class,'id_user')->withTrashed();
}
public function courier()
{
return $this->belongsTo(Courier::class,'id_courier')->withTrashed();
}
public function bank()
{
return $this->belongsTo(Bank::class)->withTrashed();
}
public function detail()
{
return $this->hasMany(DetailPenjualan::class,'no_penjualan');
}
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]