Our application send post parameters to the server via an ajax in order to generate data, format it into an excel, and then trigger a download of the created excel.
We did this previously with phpexcel, saving the excel in a tmp file, and then triggering a redirect to the route of the excel file. We are migrating our applications over to laravel but we are still doing this the same way, using the mmatwebsite laravel excel provider, saving a tmp file in the laravel public directory, and redirecting to that location. We want to download this directly without saving the in the tmp but only thing that every arrives is some garbled output in the network window.
How can this be done, and is this even possible, are we destined to use the tmp file download forver? Current simple excel function:`public function ExportCible(Request $request) {
$cible = Cible::filter($request->all())->get();
$columns = explode(",", $request->columns);
$titles = explode(",", $request->titles);
ob_end_clean();
ob_start();
$filename = "ciblage_d".date("Ymd",time())."_h".date("His",time());
Excel::create($filename, function($excel) use($cible,$columns, $titles){
$excel->sheet('Excel sheet', function($sheet)use($cible,$columns, $titles) {
$sheet->setOrientation('landscape');
$sheet->loadView('excelTemplates.cible')->with('cible', $cible)->with('columns', $columns)->with('titles', $titles);
});
})->store('xlsx', public_path('exports'));
return($filename.".xlsx");
}`
And the call on the ajax side with the window location to trigger a download.
exportData:function(url,data){
return $.ajax(url,{
data: data,
method: "POST",
success: function(fileLink){
window.location = Config.exportRoute + fileLink
},
});
},
What am I missing here. Tried the other laravel excel methods such as ->export() and ->download(). Tried similar methods in phpexcel previously. Never any luck