Class 'App\Http\Controllers\Excel' not found in Laravel
Solution 1
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.
Solution 2
After all this you need to check whether or not you have this at the top:
use Maatwebsite\Excel\Facades\Excel;
Solution 3
Sometimes, clearing configuration cache makes it work
php artisan config:cache
This should work after all you have followed all the instruction correctly but still getting "Class 'App\Http\Controllers\Excel' not found in Laravel" error
Solution 4
In laravel 5.4, First install the composer using following command
composer require maatwebsite/excel:~2.1
then, add the following in config/app.php file providers
Maatwebsite\Excel\ExcelServiceProvider::class,
then, add the following in config/app.php file aliases
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
then, add this in your controller file
use Excel;
Lulzim
Updated on August 26, 2020Comments
-
Lulzim over 3 years
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?
-
Lulzim about 9 yearsVery strange that it still doesnt work :s Call to undefined method Maatwebsite\Excel\ExcelServiceProvider::create()