subDays(config('fewo.review_request_after_days')); $bookings = Booking::query() ->whereIn('status', BookingStatus::occupying()) ->whereNull('review_requested_at') ->whereDate('departure', '<=', $latestDeparture) ->whereDate('departure', '>', $latestDeparture->copy()->subDays(30)) ->whereDoesntHave('review') ->whereHas('guest', fn ($query) => $query->whereNull('anonymized_at')->whereNotNull('email')->where('email', '!=', '')) ->with('guest') ->get() ->filter(fn (Booking $booking): bool => $booking->process()->reviewRequestSender() === Responsibility::Landlord // The step can be switched off per channel (Kanal › Ablauf); an open portal report holds it back (O4). && ProcessPlan::of($booking)->enabled('review.request') && OutwardSuspension::reason($booking) === null); foreach ($bookings as $booking) { Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReviewRequest($booking)); $booking->update(['review_requested_at' => now()]); } return $bookings->count(); } }