where([ 'student_id' => $data['student_id'], 'semester' => $data['semester'], 'school_year' => $data['school_year'] ])->first(); // If exists - UPDATE if ($existing) { return $this->update($existing['id'], $data); } // If new - INSERT else { return $this->insert($data) !== false; } } }