where('scheduled_at <= NOW()') ->where('(expires_at IS NULL OR expires_at > NOW())'); if (!empty($targetGroup)) { $builder->where('target_group', $targetGroup); } return $builder->orderBy('priority', 'DESC') ->orderBy('scheduled_at', 'DESC') ->findAll(); } /** * Get soft-deleted (archived) notifications */ public function getDeletedNotifications() { return $this->onlyDeleted() ->orderBy('deleted_at', 'DESC') ->findAll(); } /** * Get all notifications including soft-deleted */ public function getAllNotificationsWithDeleted() { return $this->withDeleted() ->orderBy('created_at', 'DESC') ->findAll(); } /** * Restore a soft-deleted notification by ID */ public function restoreNotification($id) { return $this->update($id, ['deleted_at' => null]); } /** * Cleanup expired notifications (optional for cron job use) */ public function deleteExpiredNotifications() { return $this->where('expires_at IS NOT NULL') ->where('expires_at < NOW()') ->delete(); } }