Php 未定义的方法';下载';。intelephense(1013)与Laravel中的maatwebsite/excel
我正在使用一段代码导出到excel,除了最后一行代码给出了一个未定义的方法错误外,其他一切都正常 代码如下:Php 未定义的方法';下载';。intelephense(1013)与Laravel中的maatwebsite/excel,php,laravel,laravel-8,maatwebsite-excel,Php,Laravel,Laravel 8,Maatwebsite Excel,我正在使用一段代码导出到excel,除了最后一行代码给出了一个未定义的方法错误外,其他一切都正常 代码如下: function excel() { $customer_data = DB::table('customer')->get()->toArray(); $customer_array[] = array('id', 'detail', 'emailaddress'); foreach($customer_data as $customer) {
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
}
我尝试将下载更改为存储
和加载
,但没有成功,因为您调用了错误的方法链
试用:
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');
如果我使用CreateBSite,我将调用未定义的方法Maatwebsite\Excel\Excel::create()错误。是否导入所有内容?已加载库(composer安装)?是,
使用Maatwebsite\Excel\Facades\Excel已导入代码>并且已运行composer安装