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()->guestMessages() === Responsibility::Landlord); 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(); } }