Tricks

Add bulk action to table to export selected record as JSON file within a ZIP archive

Jun 18, 2022
David VINCENT
Table builder, Admin panel
Tables\Actions\BulkAction::make('exportAllAsJson')
->label(__('Export All'))
->icon('heroicon-s-download')
->action(function (Collection $records) {
$archive = new \ZipArchive;
$archive->open('file.zip', \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
foreach ($records as $record) {
$name = Str::slug($record->name, '_') . '.json';
$return = $record->attributesToArray();
$content = json_encode($return, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
$archive->addFromString($name, $content);
}
$archive->close();
return response()->download('file.zip');
})
->deselectRecordsAfterCompletion()
avatar
Lloric Mayuga Garcia

hi, it does not work

avatar
Lloric Mayuga Garcia

im using https://github.com/barryvdh/laravel-dompdf/tree/v2.0.0

->actions([
 
Tables\Actions\Action::make('print')
->icon('heroicon-s-download')
->action(function (Order $record) {
return Pdf::loadView('filament.order.print', ['order'=>$record])
->download();
}),
avatar

I'm running in to the same issue. Same package. The download() functions returns a Response object, but the download is not starting.

avatar
LUIS ALFREDO ACOSTA

Tengo mismo el mismo problema. han aencontrado alguna solución?