Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义的方法';下载';。intelephense(1013)与Laravel中的maatwebsite/excel_Php_Laravel_Laravel 8_Maatwebsite Excel - Fatal编程技术网

Php 未定义的方法';下载';。intelephense(1013)与Laravel中的maatwebsite/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) {

我正在使用一段代码导出到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
}
我尝试将下载更改为
存储
加载
,但没有成功

,因为您调用了错误的方法链

试用:

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安装