调用未定义的方法 Maatwebsite\Excel\Excel::create() - laravel 5.6

Call to undefined method Maatwebsite\Excel\Excel::create() - laravel 5.6

我在我的应用程序中使用 Maatwebsite/Excel 时出现错误

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

来自我的一个控制器。我正在使用 laravel 5.6 并且我严格按照文档和其他很少的在线相关讨论来解决这个问题,但我仍然遇到错误。

请问如何解决这个错误

app.php

'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',

'alias' => 'Excel'=>  'Maatwebsite\Excel\Facades\Excel',

控制器

$cl = ClassModel::Select('name')->where('code',$input->class)->first();
        $input->class=$cl->name;
        $fileName=$input->class.'-'.$input->section.'-'.$input->session.'-'.$input->exam;
        // return $students;
        Excel::create($fileName, function($excel) use($input,$subjects,$students) {
            $excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
                $sheet->loadView('app.excel',compact('subjects','input','students'));
            });
        })->download('xlsx');

新版本包有很多改动。

在你的 composer.json 文件中的 require 数组中用这个替换你的包:

"maatwebsite/excel": "~2.1.0",

然后是运行composer update 这应该可以正常工作。

请切换到版本 2*

该软件包的 3.0 版尚不支持导入。此功能的发布日期未知。有关详细信息,请参阅此 post:maatwebsite

尝试使用以下方式降低版本:

composer require "maatwebsite/excel=2.1.0"

您在使用 3.* 包时使用了 2.* 语法。请在此处参考正确的文档:https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics

我已经解决了这个问题,但我知道这不是一个完美的解决方案。如果您只关心上传而不是 调整 Crudbooster 功能,它会真正帮助您。

  1. 我通过在 crudbooster-controller.

    中应用以下 CSS 从 Crudbooster 的导入屏幕中删除了额外的功能
         $this->style_css = "ul.nav li:not(:first-child) {
             display: none;
         }";
    
  2. 我从 Crudbooster CBController 复制了 getImportData() 方法,并通过以下代码在 crudbooster-controller 中覆盖了它。

//PHP
//By the way, you can still create your own method in here... :)

public function getImportData()
        {
            $this->cbLoader();
            $data['page_menu'] = Route::getCurrentRoute()->getActionName();
            $data['page_title'] = 'Import Data';

            if (request('file') && ! request('import')) {
                $file = base64_decode(request('file'));
                $file = storage_path('app/'.$file);

                $data = Excel::import(new ProductImport, $file);

                CRUDBooster::redirect('/admin/products', cbLang("alert_add_data_success"), 'success');
            }

            return view('crudbooster::import', $data);

        }

导入工作正常