where('control_ref_id', $controlId) ->where('test_ref_id', $testId) ->where('commonth', $yearMonth) ->first(); } public function saveComment($data) { $existing = $this->where('control_ref_id', $data['control_ref_id']) ->where('test_ref_id', $data['test_ref_id']) ->where('commonth', $data['commonth']) ->first(); if ($existing) { return $this->update($existing['monthly_comment_id'], $data); } else { return $this->insert($data); } } }