Laravel 错误:在 CMD 中运行 composer require laravelcollective/html 后未找到类“Collective\Html\HtmlServiceProvider”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40562140/
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 ERROR: Class 'Collective\Html\HtmlServiceProvider' not found after running composer require laravelcollective/html in CMD
提问by ITWitch
NOTE:No answer from this threadhas helped me, so far. And, I think more than 4 hours of unproductive searching for solution finally validates me to ask further help...
注意:到目前为止,该线程的任何答案都没有帮助过我。而且,我认为超过 4 个小时的徒劳的解决方案搜索最终使我能够寻求进一步的帮助......
I was following this tutorialin order to use a form in my Laravel project and allow me to save some user inputs in my database. As instructed, I executed this line via CMD:
我遵循本教程是为了在我的 Laravel 项目中使用表单并允许我将一些用户输入保存在我的数据库中。按照指示,我通过 CMD 执行了这一行:
composer require "laravelcollective/html":"^5.3.0"
Then, I've added these inside config/app.php:
然后,我在config/app.php 中添加了这些:
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
In my view, I have this, just to check if everything is now ready to be used:
在我看来,我有这个,只是为了检查现在是否一切都可以使用:
{!! Form::open([]) !!}
{!! Form::text('name', @$name) !!}
{!! Form::password('password') !!}
{!! Form::submit('Send') !!}
{!! Form::close() !!}
But then, it gave me this error:
但是后来,它给了我这个错误:
FatalThrowableError in ProviderRepository.php line 146: Class 'Collective\Html\HtmlServiceProvider' not found
ProviderRepository.php 第 146 行中的 FatalThrowableError:找不到类“Collective\Html\HtmlServiceProvider”
I even added this to my composer.json, just in case this might be the "missing ingredient":
我什至将此添加到我的 composer.json,以防万一这可能是“缺少的成分”:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0"
}
But it did not solve anything either.
但它也没有解决任何问题。
Please also note that I found two composer.json files: one inside...
另请注意,我发现了两个 composer.json 文件:一个在里面...
C:\xampp\htdocs\laravelproject
C:\xampp\htdocs\laravelproject
and another inside...
还有一个里面...
C:\xampp\htdocs\laravelproject\project
C:\xampp\htdocs\laravelproject\project
... so I edited both.
......所以我编辑了两者。
Side Note:The "project" folder is where the "original" root files can be found (e.g. the folders app, config, resources, etc.. I have previously relocated them in order to remove the word "public" from my URL.
边注:“项目”文件夹是可以找到“原始”根文件的地方(例如文件夹 app、config、resources 等。我之前已重新定位它们以从我的 URL 中删除“public”一词。
PS:I am very new to Laravel, Composer, and CMD. My only background is in PHP and CodeIgniter.
PS:我对 Laravel、Composer 和 CMD 都很陌生。我唯一的背景是 PHP 和 CodeIgniter。
Please help.
请帮忙。
I'm not sure if I should provide here the CMD result after running composer require "laravelcollective/html":"^5.3.0"(because it's 142 lines long), but I have a copy, just in case.
我不确定我是否应该在运行composer require "laravelcollective/html":"^5.3.0"后在这里提供 CMD 结果(因为它有 142 行长),但我有一份副本,以防万一。
回答by sepehr
Clearly, Laravel's Illuminate/Foundation/ProviderRepository.php
is nagging about the not-found provider:
显然,LaravelIlluminate/Foundation/ProviderRepository.php
正在唠叨未找到的提供者:
138 /**
139 * Create a new provider instance.
140 *
141 * @param string $provider
142 * @return \Illuminate\Support\ServiceProvider
143 */
144 public function createProvider($provider)
145 {
146 return new $provider($this->app);
147 }
I've just successfully tested it on a brand new installation of Laravel 5.3. Follow this checklist:
我刚刚在全新安装的 Laravel 5.3 上成功测试了它。遵循这个清单:
- Issue
composer require "laravelcollective/html":"^5.3.0"
. - Verify that the
vendor/laravelcollective/html
directory exists. - Verify that your
composer.json
file has been updated and there's an entry forlaravelcollective/html
package in your dependencies (require
block). - Add
Collective\Html\HtmlServiceProvider::class
to yourproviders
array ofconfig/app.php
. - Add
'Form' => Collective\Html\FormFacade::class
and'Html' => Collective\Html\HtmlFacade::class
to youraliases
array. - Confirm that the API exists: Issue a
php artisan tinker
command and try playing withForm::
APIs. See if throws any errors.
- 问题
composer require "laravelcollective/html":"^5.3.0"
。 - 验证
vendor/laravelcollective/html
目录是否存在。 - 验证您的
composer.json
文件是否已更新,并且laravelcollective/html
您的依赖项(require
块)中有一个package条目。 - 添加
Collective\Html\HtmlServiceProvider::class
到您providers
的config/app.php
. - 添加
'Form' => Collective\Html\FormFacade::class
和'Html' => Collective\Html\HtmlFacade::class
到您的aliases
阵列。 - 确认 API 存在:发出
php artisan tinker
命令并尝试使用Form::
API。查看是否抛出任何错误。
You might have already done all these steps. If that's the case, just remove the package with a composer remove laravelcollective/html
command and redo all the steps again.
您可能已经完成了所有这些步骤。如果是这种情况,只需使用composer remove laravelcollective/html
命令删除包并重新执行所有步骤即可。
And most importantly, get an idea of where your project files reside. Get rid of that extra project/
.
最重要的是,了解您的项目文件所在的位置。摆脱那个额外的project/
.