【发布时间】:2014-08-26 17:41:34
【问题描述】:
您好,我正在尝试将数据库表用户导出到 csv 文件,并且我在控制器中使用以下方法:
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, "\n"), 200, $headers);
}
但是当我打开“ExportFileName.csv”时,我没有得到列标题,并且还得到了一些不在数据库中的其他垃圾?
在 Laravel 4 中最好和最简单的方法是什么
谢谢
【问题讨论】:
标签: php mysql laravel laravel-4