where('student_id', $studentId) ->where('code', $code) ->where('incident_date', $incidentYmd) ->where('channel', $channel); if ($to) $qb->where('to_address', $to); $row = $qb->orderBy('id','DESC')->first(); return $row && ($row['status'] ?? '') === 'sent'; } }