subDays((int) $this->option('inactive-days')); $cooldownSince = now()->subDays((int) $this->option('cooldown-days')); $users = User::query() ->whereNotNull('email_verified_at') ->where('created_at', '<=', $inactiveSince) ->whereDoesntHave('workoutSessions', function ($q) use ($inactiveSince) { $q->whereNotNull('completed_at')->where('completed_at', '>=', $inactiveSince); }) ->where(function ($q) use ($cooldownSince) { $q->whereNull('last_reminder_sent_at')->orWhere('last_reminder_sent_at', '<', $cooldownSince); }) ->get(); foreach ($users as $user) { $user->notify(new InactivityReminder()); $user->last_reminder_sent_at = now(); $user->save(); } $this->info("Sent inactivity reminders to {$users->count()} user(s)."); return self::SUCCESS; } }