Class 'App\Http\Controllers\Excel' not found in Laravel
Asked Answered
S

4

13

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?

Sommersommers answered 10/5, 2015 at 18:31 Comment(1)
Did you run composer dump from terminal/command prompt to update the autoloader?Richard
C
24

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.

Catkin answered 10/5, 2015 at 18:42 Comment(1)
Very strange that it still doesnt work :s Call to undefined method Maatwebsite\Excel\ExcelServiceProvider::create()Sommersommers
A
6

After all this you need to check whether or not you have this at the top:

use Maatwebsite\Excel\Facades\Excel;
Ailey answered 17/11, 2017 at 16:54 Comment(0)
R
5

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

Rainie answered 12/7, 2017 at 16:32 Comment(0)
F
3

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;
Fortnightly answered 31/5, 2020 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.