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

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵