purchase_order_id = $purchaseOrderOtherCostAttr->getPurchaseOrderId(); $data->other_cost_id = $purchaseOrderOtherCostAttr->getOtherCostId(); $data->ref_pr = $purchaseOrderOtherCostAttr->getRefPr(); $data->price = $purchaseOrderOtherCostAttr->getPrice(); $data->save(); return $data; } public function delete($id) { $res = PurchaseOrderOtherCost::where('purchase_order_id', $id); $res->delete(); return $res; } public function fetch($purchaseOrderId) { $res = PurchaseOrderOtherCost::where('purchase_order_id', $purchaseOrderId)->first(); } public function getUsedQty($otherCostId, $projectId) { return PurchaseOrderOtherCost::whereHas('purchaseOrder', function ($query) use ($projectId) { $query->where('project_id', $projectId); })->where('other_cost_id', $otherCostId)->first()->qty ?? 0; } }