$form->where('needs_prevention', true)) ->where( fn ($q) => $q ->where('last_remembered_at', '<=', now()->subWeeks(2)) ->orWhereNull('last_remembered_at') ); foreach ($query->get() as $participant) { if (count($participant->preventions()) === 0) { return; } Mail::send(new PreventionRememberMail($participant)); $participant->update(['last_remembered_at' => now()]); } } }