<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class PenjualanEtalase extends Model
{
use SoftDeletes;
protected $guarded = [];
protected $primaryKey = "no_penjualan";
public $incrementing = false;
public function detail()
{
return $this->hasMany(DetailPenjualanEtalase::class,'no_penjualan');
}
public function getJumlahAttribute()
{
$jumlah = 0;
foreach ($this->detail as $e) {
$jumlah += $e->qty * $e->harga;
}
return $jumlah;
}
public function delete(){
$this->detail()->delete();
parent::delete();
}
public function ongkir()
{
return $this->belongsTo(Ongkir::class);
}
public function getOngkosKirimAttribute()
{
return $this->ongkir->harga ?? 0;
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]