ppn; return $this->sale->ppn ? HelperService::ppn($value, $ppn) * $this->qty : $value * $this->qty; } ); } public function product() { return $this->belongsTo(Product::class, "product_number", "number"); } public function sale() { return $this->belongsTo(Sale::class, "sale_number", "number"); } public function scopeHistoryProductSale($query, array $filters) { $query ->when($filters["productNumber"] ?? null, function ( $query, $search ) { $query->where("product_number", $search); }) ->when($filters["customerId"] ?? null, function ($query, $search) { $query->whereHas("sale", function ($query) use ($search) { $query->where("customer_id", $search); }); }); } }