Laravel版本:5.2.45 PHP版本:PHP版本7.0.22-0ubuntu0.16.04.1
调用未定义的方法Symfony \ Component \ HttpFoundation \ StreamedResponse :: status() 我试图使用以下代码下载csv,但收到错误
我的代码:
$headers = array(
"Content-type" => "text/csv",
"Content-Disposition" => "attachment; filename=file.csv",
"Pragma" => "no-cache",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Expires" => "0",
);
$columns = array('userId', 'action', 'value', 'ipAddress', 'createdOn');
$callback = function () use ($data, $columns) {
$file = fopen('php://output', 'w');
fputcsv($file, $columns);
foreach ($data as $item) {
fputcsv($file, array($item['userId'], $item['action'], $item['value'], $item['ipAddress'], $item['createdOn']));
}
fclose($file);
};
return FacadeResponse::stream($callback, 200, $headers);
答案 0 :(得分:0)
use Response;
,然后编辑此行:
return FacadeResponse::stream($callback, 200, $headers);
到此:
return Response::stream($callback, 200, $headers);