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

user9653376 picture user9653376 · May 18, 2018 · Viewed 10.2k times · Source

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

Call to undefined method 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.

How do i solve this error please

app.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');

Answer

Patrick Brouwers picture Patrick Brouwers · May 22, 2018

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