loadMissing(['guest', 'property']); return view('self-service.release', [ 'booking' => $booking, 'canRelease' => in_array($booking->status, BookingStatus::holding(), true) && $booking->isHoldActive(), 'released' => $booking->status === BookingStatus::Declined && $booking->declined_by === 'guest', 'action' => $this->signed('reservations.release.confirm', $booking, now()->addHour()), 'title' => 'Zeitraum freigeben', ]); } public function release(Booking $booking, ReleaseReservation $release): RedirectResponse { try { $release->handle($booking); } catch (ReservationException $exception) { return redirect()->to($this->signed('reservations.release', $booking, now()->addDays(2)))->with('self-service.error', $exception->getMessage()); } return redirect()->to($this->signed('reservations.release', $booking, now()->addDays(30)))->with('self-service.success', 'Vielen Dank – der Zeitraum ist wieder freigegeben.'); } public function showCancel(Booking $booking, CancelBookingByGuest $cancel): View { $booking->loadMissing(['guest', 'property']); $open = in_array($booking->status, BookingStatus::occupying(), true) && ! $booking->arrival->isPast(); return view('self-service.cancel', [ 'booking' => $booking, 'canCancel' => $open && ! $booking->cancellationRequested(), 'alreadyAsked' => $booking->status === BookingStatus::Cancelled || $booking->cancellationRequested(), 'instant' => $cancel->modeFor($booking) === CancellationMode::Instant, 'action' => $this->signed('bookings.cancel.confirm', $booking, now()->addHour()), 'title' => 'Buchung stornieren', ]); } public function cancel(Request $request, Booking $booking, CancelBookingByGuest $cancel): RedirectResponse { $data = $request->validate(['message' => ['nullable', 'string', 'max:1000']]); $back = fn (int $days): string => $this->signed('bookings.cancel', $booking, now()->addDays($days)); try { $outcome = $cancel->handle($booking, $data['message'] ?? null); } catch (ReservationException $exception) { return redirect()->to($back(2))->with('self-service.error', $exception->getMessage()); } $success = match ($outcome) { CancellationMode::Instant => 'Ihre Buchung ist storniert. Eine Bestätigung haben wir Ihnen per E-Mail gesendet.', CancellationMode::Request => 'Wir haben Ihren Stornierungswunsch erhalten. Ihre Buchung bleibt bestehen, bis wir uns bei Ihnen gemeldet haben.', default => 'Ihr Stornierungswunsch liegt uns bereits vor.', }; return redirect()->to($back(30))->with('self-service.success', $success); } private function signed(string $name, Booking $booking, DateTimeInterface $expiration): string { $parameters = ['booking' => $booking]; return $booking->website()?->temporarySignedRoute($name, $expiration, $parameters) ?? URL::temporarySignedRoute($name, $expiration, $parameters); } }