F
Filament10mo ago
Omid

Good practice to create a route to a PDF download?

I want to create a PDF download link, I'm using Spatie's laravel-pdf However when for example defining a route in a resource 'generate' => Pages\GenerateDocument::route('/{record}/download') the page needs to extend extends Page but can't override the render()
1 Reply
dwiser
dwiser10mo ago
It might not be exactly what you're asking for but I've done something similar with just a custom action button:
Tables\Actions\Action::make('download')
->label('Download')
->icon('heroicon-o-arrow-down-tray')
->action(function (Document $record) {
$media = $record->getFirstMedia('documents'); // Using Spatie Media Library

return response() // Laravel response helper
->download( // Docs: https://laravel.com/docs/10.x/responses#file-downloads
$media->getPath(),
$media->name . '.' . $media->extension // Optional. Setting the original filename
);
})
Tables\Actions\Action::make('download')
->label('Download')
->icon('heroicon-o-arrow-down-tray')
->action(function (Document $record) {
$media = $record->getFirstMedia('documents'); // Using Spatie Media Library

return response() // Laravel response helper
->download( // Docs: https://laravel.com/docs/10.x/responses#file-downloads
$media->getPath(),
$media->name . '.' . $media->extension // Optional. Setting the original filename
);
})
Want results from more Discord servers?
Add your server