loadMissing(['guest', 'property']); $filename = $draft ? "contracts/Angebot-{$booking->reference}-v{$booking->offer_version}.pdf" : "contracts/Mietvertrag-{$booking->reference}.pdf"; $path = "contracts/tenants/{$booking->tenant_id}/bookings/{$booking->id}/".basename($filename); // The logo is embedded as a file: the PDF is rendered on the server and must not depend on // fetching anything over the network. Each website has its own (A14). $logo = $booking->website()?->brandPath(Site::BRAND_DOCUMENT_LOGO); // The final contract is a document of record: once stored it is never rewritten (confirmation resends reuse it). if (! $draft && $booking->contract_path !== null && Storage::disk(self::DISK)->exists($booking->contract_path)) { return $booking->contract_path; } $document = OfferTerms::document($booking); $pdf = Pdf::loadView($document !== null ? 'pdf.contract-document' : 'pdf.contract', [ 'booking' => $booking, 'draft' => $draft, 'logo' => $logo, 'document' => $document, ])->setPaper('a4')->output(); Storage::disk(self::DISK)->put($path, $pdf); $booking->update([$draft ? 'offer_path' : 'contract_path' => $path, $draft ? 'offer_pdf_sha256' : 'contract_pdf_sha256' => hash('sha256', $pdf)]); return $path; } public function absolutePath(Booking $booking, bool $draft = false): ?string { $path = $draft ? $booking->offer_path : $booking->contract_path; return $path && Storage::disk(self::DISK)->exists($path) ? Storage::disk(self::DISK)->path($path) : null; } }