hasPdf()) { return self::processPdfFromEvent($event); } // Fall back to default PDF generation return DomPDF::loadView('pdf.invoice', ['invoice' => $invoice]); } private static function processPdfFromEvent(GeneratePdf $event) { // If it's already a DomPDF instance, return it if ($event->pdf) { return $event->pdf; } // If it's a file path, create a wrapper if ($event->pdfPath) { return new FilePdfWrapper($event->pdfPath, $event->fileName); } // If it's content (base64, binary, etc.), create a wrapper if ($event->pdfContent) { return new ContentPdfWrapper($event->pdfContent, $event->fileName); } // This shouldn't happen, but fallback just in case return DomPDF::loadView('pdf.invoice', ['invoice' => $event->invoice]); } }