Class 'App\Http\Controllers\Excel' not found in Laravel

Lulzim picture Lulzim · May 10, 2015 · Viewed 33.5k times · Source

In my controller I have the code as below:

Excel::create('Laravel Excel', function($excel) {

        $excel->sheet('Excel sheet', function($sheet) {

            $sheet->setOrientation('landscape');

        });

    })->export('xls');

In config/app.php in aliases array i have defined this:

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

I dont know why i cant make it work this library... Any idea?

Answer

Marcin Nabiałek picture Marcin Nabiałek · May 10, 2015

Instead of Excel::create you should use \Excel::create or add at the beginning of your file after current namespace use Excel; and then you will be able to use Excel::create

And the second error is that you used:

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

and you should use:

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

instead according to the docs.