如何解决Laravel 中带有 maatwebsite/excel 的未定义方法 'download'.intelephense(1013)
我正在使用一段代码导出到 excel 并且一切正常,除了最后一行代码给出了未定义的方法错误
代码如下:
function excel()
{
$customer_data = DB::table('customer')->get()->toArray();
$customer_array[] = array('id','detail','emailaddress');
foreach($customer_data as $customer) {
$customer_array[] = array(
'id' => $customer->id,'detail' => $customer->detail,'emailaddress' => $customer->emailaddress
);
}
Excel::download('Customer Data',function($excel) use ($customer_array){
$excel->setTitle('Customer Data');
$excel->sheet('Customer Data',function($sheet) use ($customer_array){
$sheet->fromArray($customer_array,null,'A1',false,false);
});
})->download('xlsx'); //This is the line that's giving the error message
}
我尝试将下载更改为 store
和 load
,但没有成功
解决方法
根据 documentation,您调用了错误的方法链。
尝试使用:
Excel::create('Filename',function($excel) {
})->download('xls');
或者在您的情况下:
Excel::create('Customer Data',function($excel) use ($customer_array){
$excel->setTitle('Customer Data');
$excel->sheet('Customer Data',function($sheet) use ($customer_array){
$sheet->fromArray($customer_array,null,'A1',false,false);
});
})->download('xlsx');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。