period === 'morning' ? 'scheduled_morning' : 'scheduled_evening'; // Plans that allow scheduled WhatsApp updates $eligiblePlanNames = Plan::where('active', true) ->where('whatsapp_scheduled_updates', '>', 0) ->pluck('name') ->all(); if (empty($eligiblePlanNames)) { return; } // Users who have whatsapp preference enabled $userIds = UserNotificationPreference::where('channel', 'whatsapp') ->where('enabled', true) ->distinct() ->pluck('user_id'); User::whereIn('id', $userIds) ->each(function (User $user) use ($triggerType, $eligiblePlanNames): void { $features = PlanFeatures::for($user); // Skip if their tier isn't eligible or daily limit is hit if (! in_array($features->tier(), $eligiblePlanNames, strict: true)) { return; } if (! $features->canSendNow('whatsapp')) { return; } DispatchUserNotificationJob::dispatch($user, $triggerType, fuelType: 'all'); }); } }