douyi5961 2016-11-12 11:00
浏览 201
已采纳

Laravel错误:运行composer后找不到类'Collective \ Html \ HtmlServiceProvider'需要在CMD中使用laravelcollective / html

NOTE: No answer from this thread has helped me, so far. And, I think more than 4 hours of unproductive searching for solution finally validates me to ask further help...

I was following this tutorial in 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:

composer require "laravelcollective/html":"^5.3.0"

Then, I've added these inside 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

I even added this to my composer.json, just in case this might be the "missing ingredient":

"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...

C:\xampp\htdocs\laravelproject

and another inside...

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.

PS: I am very new to Laravel, Composer, and CMD. My only background is in PHP and 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.

  • 写回答

1条回答 默认 最新

  • duanpo7354 2016-11-12 12:06
    关注

    Clearly, Laravel's Illuminate/Foundation/ProviderRepository.php is nagging about the not-found provider:

    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:

    1. Issue composer require "laravelcollective/html":"^5.3.0".
    2. Verify that the vendor/laravelcollective/html directory exists.
    3. Verify that your composer.json file has been updated and there's an entry for laravelcollective/html package in your dependencies (require block).
    4. Add Collective\Html\HtmlServiceProvider::class to your providers array of config/app.php.
    5. Add 'Form' => Collective\Html\FormFacade::class and 'Html' => Collective\Html\HtmlFacade::class to your aliases array.
    6. Confirm that the API exists: Issue a php artisan tinker command and try playing with Form:: APIs. See if throws any errors.

    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.

    And most importantly, get an idea of where your project files reside. Get rid of that extra project/.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用logisim设计16位单时钟周期cpu
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应
  • ¥15 如何用字典的Key,显示在WPF的xaml中
  • ¥15 weautomate读取Excel表格信息然后填写到网页一直报错,如何解决?
  • ¥15 C#如何在Webview2中获取网页验证码
  • ¥15 esp32烧录失败,具体情况在图片上