property; if ($departure->lessThanOrEqualTo($arrival)) { throw new ReservationException('Die Abreise muss nach der Anreise liegen.'); } $booking = DB::transaction(function () use ($property, $channel, $arrival, $departure, $reference, $notes, $processingMode): Booking { $property->newQuery()->whereKey($property->id)->lockForUpdate()->firstOrFail(); if (! $this->availability->isAvailable($property, $arrival, $departure)) { throw ReservationException::notAvailable(); } $profile = $this->settings->resolve($property, $channel, IntakeKind::Inquiry); return $property->bookings()->create([ 'status' => BookingStatus::Reserved, 'source' => 'portal', 'intake' => IntakeKind::Inquiry, 'origin_channel_id' => $channel->id, 'portal_reference' => $reference, 'arrival' => $arrival->toDateString(), 'departure' => $departure->toDateString(), 'hold_expires_at' => $profile->preReservation() ? now()->addHours($profile->holdHours()) : null, 'processing_mode' => $processingMode, 'internal_notes' => $notes, ]); }); app(CaseAutomation::class)->advance($booking); return $booking->refresh(); } }