doonkaiji
doonkaiji
FFilament
Created by doonkaiji on 4/8/2024 in #❓┊help
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
3 replies