F
Filament9mo ago
Sidem

Export didn't work

Hi, i can't make the user to dowload the file but the link is good and when i put it on an other tab of my google, it work : there is my code in app\Services\ExportService.php :
public static function export($datas, $type)
{

//... my code

$writer->save($excelFile);
$filename = $name . now()->format('Y-m-d_H-i-s') . '.xlsx';
$filePath = 'public/' . $filename;
Storage::disk('local')->put($filePath, file_get_contents($excelFile));
unlink($excelFile);
return response()->download(storage_path('app/' . $filePath), $filename);
}
public static function export($datas, $type)
{

//... my code

$writer->save($excelFile);
$filename = $name . now()->format('Y-m-d_H-i-s') . '.xlsx';
$filePath = 'public/' . $filename;
Storage::disk('local')->put($filePath, file_get_contents($excelFile));
unlink($excelFile);
return response()->download(storage_path('app/' . $filePath), $filename);
}
if i do
dd(return response()->download(storage_path('app/' . $filePath), $filename));
dd(return response()->download(storage_path('app/' . $filePath), $filename));
it will send me a link that will download the file if I put it on another Google tab
2 Replies
toeknee
toeknee9mo ago
Are you using an action? If so you need the response download on the action it's self. I belive, so the export function should return the full file path and the action should return the response.
Sidem
Sidem9mo ago
yes i use this :
Actions\Action::make('Export')
->action(function (): void {
ExportService::export(["data" => Demande::where('id', '<=', 15)->get()], "Demande");
}),
Actions\Action::make('Export')
->action(function (): void {
ExportService::export(["data" => Demande::where('id', '<=', 15)->get()], "Demande");
}),
so i modify to this and this work ! thank you a lot !
Tables\Actions\Action::make('Export')
->action(function () {
return ExportService::export(["data" => Demande::where('id', '<=', 15)->get()], "Demande");
})
Tables\Actions\Action::make('Export')
->action(function () {
return ExportService::export(["data" => Demande::where('id', '<=', 15)->get()], "Demande");
})