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 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题