Laravel 5.1: Class html does not exist

早过忘川 提交于 2019-11-27 03:21:00

问题


I am upgrading from 4.2 directly to 5.1 and run into problems with the Html and Form classes.

I followed the upgrade notes, and did

  • add "laravelcollective/html": "~5.0" to composer.json
  • composer update
  • add Collective\Html\HtmlServiceProvider::class to providers in app.php
  • add Form' => Collective\Html\FormFacade::class, Html' => Collective\Html\HtmlFacade::class to aliases in app.php

But my views don't work. I get either Class HTML does not exist when using HTML::router or get Class html does not exist when using link_to_route

I also tried Illuminate\html instead of laravelcollective, I did a composer dump-autoload.

The complete errors:

ErrorException in Container.php line 736: Class html does not exist (View: C:\Dev\www\admin\resources\views\clubs\index.blade.php)
ReflectionException in Container.php line 736: Class html does not exist

What am I missing?


I tried everyone's answers and none of them worked for me for some reason. Ultimately I created a completely new laravel application, copied my code and then it started working, So though solved the actual problem remains a mystery.


回答1:


Add in composer.json

 "illuminate/html": "5.*"

and run composer update

Open your config/app.php

add under 'providers'

Illuminate\Html\HtmlServiceProvider::class,

add under 'aliases'

'Form'      => Illuminate\Html\FormFacade::class,
'Html'      => Illuminate\Html\HtmlFacade::class,

and under your blade templates, use as such

{!! HTML::style('assets/css/flatten.css') !!}



回答2:


My solution in my case it was problem with CASE-Sensitive class name.

In my config/app.php (in aliases)
'Form'      => Collective\Html\FormFacade::class,
'Html'      => Collective\Html\HtmlFacade::class,

I am tried to use in view this code:

{!! HTML::mailto('mailto:example@example.com', 'example@example.com'); !!}

and that was an error:

"FatalErrorException in ccf70b1d0b9930d6c4e8f3859fff448f line 11: Class 'HTML' not found"

Name of class 'HTML' is CASE-Sensitive. You should use 'Html' as in your config (config/app.php) file.

Hope this help for some people.




回答3:


Please change your blade file from this

{{ HTML::style('css/bootstrap.min.css') }}

to

{{ Html::style('css/bootstrap.min.css') }}

It's working.




回答4:


A simple restart after composer update worked perfectly for me. I was looking for the answer, and got stuck at the same position. I'd suggest, run config:cache and cache:clear and restart the IDE. It will work.




回答5:


My problem is solved, but the actual cause is still unknown. I have created a completely new laravel install and copied my source (all of it). The new application worked right away (after installing illuminate/html).

So you think I did something wrong with packages? That's what I thought, and then I did a diff on the two directories, only to find out they were identical. So it's a real mystery.

So, now everything is working, I simply renamed my new application and can continue.

I do know at some point I probably had both the collective and the illuminate versions of the HTML package installed. That's what most likely corrupted everything.




回答6:


this is right way If you try to use Form::open() or any of the Form methods in a fresh Laravel 5 install, you would get something like this: http://laraveldaily.com/class-form-not-found-in-laravel-5/




回答7:


I think I have found the solution.

In your app.php you have declared

'Form'      => Illuminate\Html\FormFacade::class,
'Html'      => Illuminate\Html\HtmlFacade::class,

While in your View you have called the same class as

{!! HTML::style('css/bootstrap.min.css') !!}

There is nothing wrong with the packages as the marked answer above but rather difference in capitalization of the word HTML as the previous documentation ver 5.0.*.

It should be

'Form'      => Illuminate\Html\FormFacade::class,
'HTML'      => Illuminate\Html\HtmlFacade::class,



回答8:


Try it

php artisan cache:clear

php artisan clear-compiled




回答9:


edit config/app.php

add this into providers

Collective\Html\HtmlServiceProvider::class,

and this into aliases

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,


来源:https://stackoverflow.com/questions/31350030/laravel-5-1-class-html-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!