找不到 Laravel 服务提供者
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22826874/
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
Laravel service provider is not found
提问by Peter Hon
When I access laravel, it said
当我访问laravel时,它说
Symfony \ Component \ Debug \ Exception \ FatalErrorException
'Krucas\Notification\NotificationServiceProvider' Not found
The Website locations is http://somedomain.com/index.phpIt's document physical path is :
网站位置是http://somedomain.com/index.php它的文档物理路径是:
C:/Apache24/htdocs/new_project/laravel/public/laravel1/public
And I have these setting in
我有这些设置
C:/Apache24/htdocs/new_project/laravel/public/laravel1/app/config/app.php
providers array 'Krucas\Notification\NotificationServiceProvider'
提供者数组 'Krucas\Notification\NotificationServiceProvider'
Alias Array 'Notification'=> 'Krucas\Notification\Facades\Notification'
别名数组 'Notification'=> 'Krucas\Notification\Facades\Notification'
How can I know the Laravel maps the provider array and alias array to the physical path?
我怎么知道 Laravel 将提供者数组和别名数组映射到物理路径?
回答by 4givN
There were some cases with registration problem, cache issues, etc. Try one of these solutions:
在某些情况下会出现注册问题、缓存问题等。请尝试以下解决方案之一:
- register your provider (in main composer.json, then in config/app.php [provider & alias] ), then run
composer dump-autoload
- make sure you have initiated your package : go to the folder, then
composer init
- try
php artisan config:cache
or delete everything inbootstrap/cache/
- 注册您的提供者(在主 composer.json 中,然后在 config/app.php [provider & alias] 中),然后运行
composer dump-autoload
- 确保您已启动您的包:转到文件夹,然后
composer init
- 尝试
php artisan config:cache
或删除所有内容bootstrap/cache/
回答by Shafiul
After adding the dependency in composer.json, you have to install the package before adding the class in service provider, using the below command:
在 composer.json 中添加依赖项后,您必须在服务提供者中添加类之前安装包,使用以下命令:
composer update
You can easily check if the physical file(NotificationServiceProvider) exists in your project. If it does not exists, you need to install the package using above command(don't forget to comment out the service provider declaration in app.php and re-enable after installing the package.)
您可以轻松检查项目中是否存在物理文件(NotificationServiceProvider)。如果不存在,则需要使用上述命令安装该包(不要忘记在app.php中注释掉服务提供者声明并在安装该包后重新启用。)