Files
fewo-stommer/app/Actions/RequestReviews.php
T
Lars StommerandClaude Opus 5.5 2892e6aeab Gästeverzeichnis und Customer Voice
- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist)
- Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks
- Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin
- Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:26:11 +02:00

38 lines
1.2 KiB
PHP

<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Mail\ReviewRequest;
use App\Models\Booking;
use Illuminate\Support\Facades\Mail;
/**
* Sends the review invitation once, a few days after departure. Old stays (more than 30 days ago)
* are skipped so that switching the feature on does not mail former guests.
*/
class RequestReviews
{
public function handle(): int
{
$latestDeparture = today()->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'))
->with('guest')
->get();
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();
}
}