Download action button behaves weirdly

I have a table action that redirects the user to this route ('tickets/{id}/files')
Tables\Actions\Action::make('download_all_files')
->label('Download All Files')
->icon('heroicon-m-arrow-down-on-square-stack')
->color('primary')
->hidden(!(auth()->user()->can('can_download_all_files_ticket')))
->action(function (Ticket $record): void {
Redirect::to('/tickets/' . $record->id . '/files');
}),
Tables\Actions\Action::make('download_all_files')
->label('Download All Files')
->icon('heroicon-m-arrow-down-on-square-stack')
->color('primary')
->hidden(!(auth()->user()->can('can_download_all_files_ticket')))
->action(function (Ticket $record): void {
Redirect::to('/tickets/' . $record->id . '/files');
}),
Everything in the
__invoke
__invoke
function is working fine and I am able to download all the ticket's files in a zip format
public function __invoke(Request $request)
{
// ...
$files = $ticket->getMedia();
if (count($files) === 0) {
Notification::make()
->title('No files to download')
->warning()
->send();
return redirect()->back();
}
$zip = new ZipArchive();
$fileName = 'ticket-' . $ticket->ticket_identifier . '-attachments.zip';
$zip->open($fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($files as $file) {
$filePath = storage_path('app/public/' . $file);
$zip->addFile($filePath, $file);
}
$zip->close();
Notification::make()
->title('Files downloaded')
->success()
->send();
return response()->download($fileName)->deleteFileAfterSend(true);
}
public function __invoke(Request $request)
{
// ...
$files = $ticket->getMedia();
if (count($files) === 0) {
Notification::make()
->title('No files to download')
->warning()
->send();
return redirect()->back();
}
$zip = new ZipArchive();
$fileName = 'ticket-' . $ticket->ticket_identifier . '-attachments.zip';
$zip->open($fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($files as $file) {
$filePath = storage_path('app/public/' . $file);
$zip->addFile($filePath, $file);
}
$zip->close();
Notification::make()
->title('Files downloaded')
->success()
->send();
return response()->download($fileName)->deleteFileAfterSend(true);
}
After downloading the zip file there are two notifications, why? When I click the button again, an empty form appears. Pressing the submit button downloads the files. When I click the button again on another row, the pervious file is downloaded again What causes these issues?
No description
No description
No description
2 Replies
DrByte
DrByte12mo ago
I wonder if it's the redirect? Is the redirect necessary?
awcodes
awcodes12mo ago
Why even do the redirect? Just put the logic in the action.
Want results from more Discord servers?
Add your server