where('student_id', (int)$data['student_id']) ->where('school_year_to', (string)$data['school_year_to']) ->first(); if ($existing) { return (bool) $this->update((int)$existing[$this->primaryKey], array_merge($existing, $data)); } return (bool) $this->insert($data); } }