在 Laravel 5.8 中调用未定义的方法 Maatwebsite\Excel\Excel::create()

Call to undefined method Maatwebsite\Excel\Excel::create() in Laravel 5.8

我正在使用 Laravel 5.8 和 maatwebsite/excel 3.1 导出到 Excel 但出现错误。

Call to undefined method Maatwebsite\Excel\Excel::create()

我已经在Controller和View中写好了导出代码

config/app.php

        /*
         * Package Service Providers...
         */
Maatwebsite\Excel\ExcelServiceProvider::class, 

//Class Aliases
'Excel' => Maatwebsite\Excel\Facades\Excel::class,

控制器

use Excel;

     public function msisdnExport() 
    {
     $msisdns = User::select( 
               "phone"
             )       
               ->get();  

     // Initialize the array which will be passed into the Excel
     // generator.
     $msisdnsArray = []; 

     // Define the Excel spreadsheet headers
     $msisdnsArray[] = ['MSISDN'];

     // Convert each member of the returned collection into an array,
     // and append it to the payments array.
     foreach ($msisdns as $msisdn) {
          $msisdnsArray[] = $msisdn->toArray();
     }

     // Generate and return the spreadsheet
    // Excel::create('MSISDN', function($excel) use ($msisdnsArray) {
        Excel::download('MSISDN', function($excel) use ($msisdnsArray) {

          // Set the spreadsheet title, creator, and description
          $excel->setTitle('MSISDN');
          $excel->setCreator('Developers')->setCompany('Cloud Africa');
          $excel->setDescription('users msisdn file');

          // Build the spreadsheet, passing in the payments array
          $excel->sheet('sheet1', function($sheet) use ($msisdnsArray) {
               $sheet->fromArray($msisdnsArray, null, 'A1', false, false);
          });

     })->download('xlsx');
} 

查看

<a href="{{ route('msisdn-export') }}" class="btn btn-block btn-primary" style="margin-right: 15px;"><i class="fa fa-file-excel-o"></i> Excel</a>

当我在视图中单击 Excel 时,它应该导出到 excel 但出现此错误。

Call to undefined method Maatwebsite\Excel\Excel::create()

create 方法已被删除。您必须使用以下其中一项:

Excel::download($yourExport);
Excel::store($yourExport);

如升级指南中所述:

Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)

来源:https://docs.laravel-excel.com/3.1/getting-started/upgrade.html#upgrading-to-3-from-2-1