Search code examples
phplaravelnamespaceslaravel-excel

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


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?


Solution

  • 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.