'required|string|max_length[9]', ]; protected $useTimestamps = true; protected $createdField = 'created_at'; protected $updatedField = 'updated_at'; public function upsert(array $data): bool { if (empty($data['student_id']) || empty($data['school_year_to'])) { return false; } $data['school_year'] = (string)($data['school_year'] ?? $data['school_year_from'] ?? $data['school_year_to']); $existing = $this->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); } }