Requesting Assistance for PDF Download Issue Upon Record Creation in Laravel Application

I'm seeking assistance from Filament support regarding an issue with downloading a PDF after creating a record in my Laravel application. Here's a detailed breakdown of the problem: In my application, I have a PDF controller named DownloadPdfController, which is responsible for generating and downloading PDFs. Here's a snippet of the controller code: class DownloadPdfController extends Controller { public function download() { // Retrieving the first Colis record $colis = Colis::all()->first(); // Generating barcode HTML $barcode = new DNS1D(); $codebar = $barcode->getBarcodeHTML($colis->{'Numéro de suivi'}, 'C39'); // Data to be passed to the PDF view $data = [ 'title' => 'Colis Ticket - ' . $colis->{'Numéro de suivi'}, 'colis' => $colis, 'codebar' => $codebar, ]; // Generating PDF from view $pdf = Pdf::loadView('Colis.Pdf.Colis-Ticket-Pdf', $data); // Downloading the PDF with a specific filename return $pdf->download('colis-ticket-' . $colis->{'Numéro de suivi'} . '.pdf'); } } Additionally, I have a method named afterCreate() in my CreateColis.php file, which should trigger the PDF download after a record is created. Here's a snippet of the code: protected function afterCreate(): void { app(DownloadPdfController::class)->download(); } protected function getRedirectUrl(): string { app(DownloadPdfController::class)->download(); return $this->getResource()::getUrl('index'); } I've confirmed that the method app(DownloadPdfController::class)->download(); is triggered after record creation, generating the PDF successfully. However, the PDF isn't automatically downloaded despite the method being called.Strangely, when I manually test the PDF download by calling the method through a route, it works perfectly fine. Assistance in resolving this discrepancy would be appreciated. Thank you
1 Reply
hashim199
hashim1992mo ago
i am also stuck in this. i want to generate pdf after creating record. when the user click on create it should fetch the current and generate its pdf > i have placed dd in the controller and view it works fine but it doesnot download the pdf 😦 protected function mutateFormDataBeforeCreate(array $data): array { $controller = new BillPanelReports(); $controller->tess($data); return $data; } class BillPanelReports extends Controller { public function tess( $data) { //dd($data); $pdf = PDF::loadView('printbill', compact('data')); // Download the PDF with the specified file name return $pdf->download('Bill.pdf'); } } Route::get('/print-bill/{data}', [BillPanelReports::class, 'tess'])->name('print-bill'); <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Print Bill</title> </head> <body> <h1>Print Bill</h1> <?php //dd($data['total']); ?></body> </html> — i have tested by making a new action it works fine but i need the pdf on create Action::make('pdf') ->icon('heroicon-o-document') ->url(function (Bill $bill) { return route('print-bill',$bill); }),