Files
fewo-stommer/app/Actions/ExpireReservations.php
2026-10-23 07:14:25 +02:00

34 lines
910 B
PHP

<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Mail\ReservationExpired;
use App\Models\Booking;
use App\Support\Settings;
use Illuminate\Support\Facades\Mail;
/**
* Marks reservations whose hold time is over as expired and tells the landlord.
* The calendar already treats them as free once the hold time is over; this only updates the status.
*/
class ExpireReservations
{
public function handle(): int
{
$expired = Booking::query()
->whereIn('status', BookingStatus::holding())
->where('hold_expires_at', '<=', now())
->with(['guest', 'property'])
->get();
foreach ($expired as $booking) {
$booking->update(['status' => BookingStatus::Expired]);
Mail::to(Settings::notificationRecipients())->send(new ReservationExpired($booking));
}
return $expired->count();
}
}