Fix – Call to undefined method maatwebsite\excel\excel::create()
Posted on: February 26, 2021 by Deven
If you are getting call to undefined method maatwebsite\excel\excel::create() error, this article will help you fix the issue.
If you are getting the above error while trying to add providers and aliases like in the code example below:
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"maatwebsite/excel": "^3.1",
"predis/predis": "^1.1",
"uxweb/sweet-alert": "^2.0"
Controller:
use Excel;
public function export_list()
{
Excel::create('Export data', function($excel) {
$excel->sheet('Sheet', function($sheet) {
$data = User::where('city','ygn')->get();
$sheet->fromArray($data);
});
})->download('xls');
}
it can be easily fixed by using Excel::download() or Excel::store()
. since ::create
has been removed in the latest release.
please note that ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0. Consider the example below:
Excel::load() is removed and replaced by Excel::import($yourImport)
Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
Excel::create()->string('xlsx') is removed an replaced by Excel::raw($yourExport, Excel::XLSX)
Share on social media
//