addHours(24); $windowStart = $targetTime->copy()->subMinutes(30); $windowEnd = $targetTime->copy()->addMinutes(30); $consultations = Consultation::query() ->where('status', ConsultationStatus::Approved) ->whereNull('reminder_24h_sent_at') ->whereDate('booking_date', $targetTime->toDateString()) ->get() ->filter(function ($consultation) use ($windowStart, $windowEnd) { $consultationDateTime = Carbon::parse( $consultation->booking_date->format('Y-m-d').' '. $consultation->booking_time ); return $consultationDateTime->between($windowStart, $windowEnd); }); $count = 0; foreach ($consultations as $consultation) { try { $consultation->user->notify(new ConsultationReminder24h($consultation)); $consultation->update(['reminder_24h_sent_at' => now()]); $count++; $this->info("Sent 24h reminder for consultation #{$consultation->id}"); } catch (\Exception $e) { $this->error("Failed to send reminder for consultation #{$consultation->id}: {$e->getMessage()}"); Log::error('24h reminder failed', [ 'consultation_id' => $consultation->id, 'error' => $e->getMessage(), ]); } } $this->info("Sent {$count} 24-hour reminders"); return Command::SUCCESS; } }