I am trying to export single record from DB. I have tried to write different methods but failed. Now I try this one here, it's just downloading the headers and no data.
public function getExport($id) {
$student = Students::find($id);
$filename = "students.csv";
$handle = fopen($filename, 'w+');
fputcsv($handle, array('name', 'class', 'section'));
foreach($student as $row) {
fputcsv($handle, array($row['name'], $row['class'], $row['section']));
}
fclose($handle);
$headers = array(
'Content-Type' => 'text/csv',
);
return Response::download($filename, 'Students.csv', $headers);
}
Here it just gives the table head not data below. How can I get all?