找不到类 'Maatwebsite\\Excel\\ExcelServiceProvider' - Laravel 4.2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54083863/
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 'Maatwebsite\\Excel\\ExcelServiceProvider' not found - Laravel 4.2
提问by cyber8200
I'm using Laravel 4.2, after running php artisan migrate
I got
我正在使用 Laravel 4.2,运行后php artisan migrate
我得到了
PHP Fatal error: Class 'Maatwebsite\Excel\ExcelServiceProvider' not found in /home/forge/site/distributor-portal/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
PHP Stack trace:
PHP 1. {main}() /home/forge/site/distributor-portal/artisan:0
PHP 2. require_once() /home/forge/site/distributor-portal/artisan:30
PHP 3. require() /home/forge/site/distributor-portal/bootstrap/start.php:68
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/forge/site/distributor-portal/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/forge/site/distributor-portal/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:57
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/forge/site/distributor-portal/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:121
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Maatwebsite\Excel\ExcelServiceProvider' not found","file":"\/home\/forge\/site\/distributor-portal\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php","line":157}}
This is what I have in composer.json
这就是我所拥有的 composer.json
"maatwebsite/excel": "~1.3"
I am running on PHP 5.6.
我在PHP 5.6上运行。
Maatwebsite\Excel\ExcelServiceProvider
Maatwebsite\Excel\ExcelServiceProvider
How do I avoid this ? Is this something that I did in one of my migration files ?
我如何避免这种情况?这是我在我的一个迁移文件中所做的事情吗?
回答by Udhav Sarvaiya
For Laravel 4
对于Laravel 4
Add this line to composer.json
将此行添加到 composer.json
"maatwebsite/excel": "~1.3",
After changes in composer.json then run composer update
在 composer.json 更改后运行 composer update
Add the ServiceProvider to the providers array in config/app.php
like:
将 ServiceProvider 添加到 providers 数组中,config/app.php
如下所示:
'Maatwebsite\Excel\ExcelServiceProvider',
Add also in alias like:
还添加别名,如:
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
Publish config file:
发布配置文件:
php artisan config:publish maatwebsite/excel
// The config files can now be found at app/config/packages/maatwebsite/excel
For Laravel 5
对于Laravel 5
This will download the package and PhpSpreadsheet.just run at a command prompt:
这将下载包和 PhpSpreadsheet.just 在命令提示符下运行:
composer require maatwebsite/excel
The Maatwebsite\Excel\ExcelServiceProvider
is auto-discovered and registered by default, but if you want to register it yourself:
该Maatwebsite\Excel\ExcelServiceProvider
是自动发现,并在默认情况下注册,但如果你想自己注册它:
Add the ServiceProvider and Facade in config/app.php
在中添加 ServiceProvider 和 Facade config/app.php
'providers' => [
Maatwebsite\Excel\ExcelServiceProvider::class,
],
'aliases' => [
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]
To publish the config, run the vendor publish command:php artisan vendor:publish
This will create a new config file named config/excel.php
要发布配置,请运行供应商发布命令:php artisan vendor:publish
这将创建一个名为的新配置文件config/excel.php
回答by Ismoil Shifoev
Make sure you publish after following these steps
确保在遵循这些步骤后发布
1) add this line to composer.json
1) 将此行添加到 composer.json
"maatwebsite/excel": "~2.1.0",
then run
然后运行
composer update
2) After updating composer, add the ServiceProvider to
the providers array in app/config/app.php
like
'Maatwebsite\Excel\ExcelServiceProvider'
,
2)更新composer后,将ServiceProvider添加到app/config/app.php
like中
的provider数组中'Maatwebsite\Excel\ExcelServiceProvider'
,
and alias like so
和别名这样
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
3) And finally, publish for Laravel 5
3) 最后,为 Laravel 5 发布
`php artisan vendor:publish`
php artisan config:publish maatwebsite/excel
for Laravel 4
php artisan config:publish maatwebsite/excel
对于 Laravel 4
I hope it helps someone.!
我希望它可以帮助某人。!