How to Download a Pdf File

Hii all, i was trying to download a pdf file that pdf view page having in a blade file..i need to download a column data only..
17 Replies
Dennis Koch
Dennis Koch2y ago
No sure what's the issue? Use a link to the PDF and it should open/download?
Roshan_k
Roshan_kOP2y ago
the pdf design i have in a blade file....i used $evaluate to get data...that showing error undifined variable $evaluate
Dennis Koch
Dennis Koch2y ago
So you aren't asking about "download" but about the generation of a PDF? $evaluate is an internal method of Filament. Why are you using this in a Blade to generate a PDF? You should use the record data
Roshan_k
Roshan_kOP2y ago
okay..Thank you. i can't pass record data directley to blade file from resource Action ..is it need to create controller for that..
Dennis Koch
Dennis Koch2y ago
You can get record via Closure fn ($record) =>
Roshan_k
Roshan_kOP2y ago
okay
toeknee
toeknee2y ago
Did you get sorted?
Roshan_k
Roshan_kOP2y ago
i having ViewField can i download diretly as pdf file through ->action() Action::make('view_pdf') ->action(function () { })
toeknee
toeknee2y ago
Yeah
Roshan_k
Roshan_kOP2y ago
how...
toeknee
toeknee2y ago
I did it with an icon column within a table personally, but you can see the principle:
Tables\Columns\IconColumn::make('pdf')
->label('PDF')
->boolean()
->toggleable()
->default(1)
->trueIcon('fluentui-document-pdf-20')
->action(fn (MyModel $record) => response()->download($record->generatePdf())),
Tables\Columns\IconColumn::make('pdf')
->label('PDF')
->boolean()
->toggleable()
->default(1)
->trueIcon('fluentui-document-pdf-20')
->action(fn (MyModel $record) => response()->download($record->generatePdf())),
Roshan_k
Roshan_kOP2y ago
thank you..!
toeknee
toeknee2y ago
point in my example is the response()->download()
Dennis Koch
Dennis Koch2y ago
Return a download response
Roshan_k
Roshan_kOP2y ago
return response()->download(storagePath()) in this, how to give localstorage [download] as a storagePath ..
Quadrubo
Quadrubo2y ago
response()->download() accpets the storage path as an argument, there you should put the path of the file you want to download, see https://laravel.com/docs/10.x/responses#file-downloads
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
toeknee
toeknee2y ago
so that would be: ->download(storagePath() . '/pdfs/myfile.pdf')
Want results from more Discord servers?
Add your server