php 在 Laravel 中找不到类“App\Http\Controllers\Excel”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30155145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'App\Http\Controllers\Excel' not found in Laravel
提问by Lulzim
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:
在别名数组的 config/app.php 中,我定义了这个:
'Excel' => 'Maatwebsite\Excel\ExcelServiceProvider',
I dont know why i cant make it work this library... Any idea?
我不知道为什么我不能让它在这个库中工作......知道吗?
回答by Marcin Nabia?ek
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
而不是Excel::create
您应该\Excel::create
在当前命名空间之后的文件开头使用或添加,use Excel;
然后您就可以使用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.
而是根据文档。
回答by TharinduLucky
Sometimes, clearing configuration cache makes it work
有时,清除配置缓存使其工作
php artisan config:cache
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
在您正确遵循所有说明但仍然收到“Laravel 中未找到 Class 'App\Http\Controllers\Excel'”错误之后,这应该可以工作
回答by Mohammad Sheykholeslam
After all this you need to check whether or not you have this at the top:
毕竟,您需要检查顶部是否有这个:
use Maatwebsite\Excel\Facades\Excel;