Hi I am trying to export database table users to a csv file and I am using the following method in my controller:
public function getExport()
{
$table = User::all();
$output='';
foreach ($table as $row) {
$output.= implode(",",$row->toArray());
}
$headers = array(
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="ExportFileName.csv"',
);
return Response::make(rtrim($output, "
"), 200, $headers);
}
but when I open "ExportFileName.csv" I am getting not Columns Headers and also getting some other garbage in there that are not in the database ?
Whats the best and easy way to do this in Laravel 4
Thanks