where('controlid', $controlid) ->where('testid', $testid) ->where('commonth', $yearMonth) ->first(); } public function saveComment($data) { $existing = $this->where('controlid', $data['controlid']) ->where('testid', $data['testid']) ->where('commonth', $data['commonth']) ->first(); if ($existing) { return $this->update($existing['id'], $data); } else { return $this->insert($data); } } }