$headers = array(
"Content-type" => "text/csv;charset=Windows-1252",
"Content-Encoding" => "Windows-1252",
"Content-Disposition" => "attachment; filename=file.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0"
);
case 'exam':
$items = Exam::whereIn('id', $ids)->get();
$columns = array('id', 'name', 'surname', 'middle_name', 'phone', 'email', 'date', 'time', 'type');
$callback = function () use ($items, $columns) {
$file = fopen('php://output', 'w');
fputcsv($file, $columns);
foreach ($items as $item) {
fputcsv($file, array(
$item->id,
$item->name,
$item->surname,
$item->middle_name,
$item->phone,
$item->date,
$item->time,
$item->type
));
}
fclose($file);
};
break;
"Content-type" => "text/csv;charset=utf-8",
fputcsv($file, array(
$item->id,
mb_convert_encoding($item->name, 'cp1251', 'utf-8'),
mb_convert_encoding($item->surname, 'cp1251', 'utf-8'),
mb_convert_encoding($item->middle_name, 'cp1251', 'utf-8'),
$item->phone,
$item->date,
$item->time,
$item->type
));