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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50409366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:43:24  来源:igfitidea点击:

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

phplaravelmaatwebsite-excel

提问by

I am using Maatwebsite/Excel in my application and when i get the error

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

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

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

from one of my controllers. I am using laravel 5.6 and i have followed the documentation strictly and other very few related discussions online to solve this, but i still get the error.

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

How do i solve this error please

我该如何解决这个错误

app.php

应用程序.php

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

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

Controller

控制器

$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');

采纳答案by Zakaria Acharki

Try to decrease the version using :

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

composer require "maatwebsite/excel=2.1.0"

回答by Patrick Brouwers

You are using 2.* syntax while using 3.* package. Please refer to the correct documentation over here: https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics

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

回答by Saurabh

There have been many changes in the new version of the package.

新版本的包有很多变化。

In your composer.jsonfile inside the require array replace your package with this:

composer.jsonrequire 数组中的文件中,将您的包替换为:

"maatwebsite/excel": "~2.1.0",

"maatwebsite/excel": "~2.1.0",

and then run composer updateThis should work fine.

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

回答by AddWeb Solution Pvt Ltd

Please switch to version 2*

请切换到版本 2*

Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: maatwebsite

该软件包的 3.0 版尚未处理导入。此功能的发布日期未知。有关更多详细信息,请参阅此帖子:maatwebsite