I have a function where I generates excel (.csv) file. Everything is working except download. So my idea was to download the file automatically in the browser after generating the csv file. When the file was generated we store it in the public folder. So when I call my function , the function is opening the url: http://127.0.0.1:8000/project/tools/export/exportData and displaying the file instead of downloading it. So for this I need your help! Thank you in advance. My codes :
public function exportData() {
$size=sizeof($arr);
for($i=0; $i<$size; $i++)
{
fputcsv($fh,$arr[$i]);
}
fclose($fh);
$file="Export.csv";
$headers = array(
'Content-Type: text/csv',
);
return response()->download($file, 'Export.csv', $headers);
}