I searched in google to generate the csv file from laravel and i have found the following code:
public function download(){
$headers = [
'Cache-Control' => 'must-revalidate, post-check=0, pre- check=0'
, 'Content-type' => 'text/csv'
, 'Content-Disposition' => 'attachment; filename=galleries.csv'
, 'Expires' => '0'
, 'Pragma' => 'public'
];
$list = User::all()->toArray();
# add headers for each column in the CSV download
array_unshift($list, array_keys($list[0]));
$callback = function() use ($list)
{
$FH = fopen('php://output', 'w');
foreach ($list as $row) {
fputcsv($FH, $row);
}
fclose($FH);
};
return Response::stream($callback, 200, $headers);
}
In the above code, i didn't understand
$callback = function() use ($list){...}
will someone please explain me?
Response::stream()andResponse::stream()will be able to execute that function