11

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.

9 Answers9

16

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') !!}
animesh manglik
  • 755
  • 7
  • 14
  • 1
    The reason being that in L5 the HTML and Form functions are an optional part of the framework. They don't include it by default because more and more people are doing all of their templating on the client side. – Kenmore Jul 11 '15 at 06:48
  • @Zuko I installed http://laravelcollective.com/docs/5.1/html which is a spin off from illuminate/html, so it's the same thing. See my new answer for more info. – Michiel van der Blonk Jul 11 '15 at 18:22
  • @MichielvanderBlonk Is the official Illuminate/Html not going to be maintained anymore? I thought it would be, and just not be included by the framework by default. – Kenmore Jul 12 '15 at 07:45
  • @Zuko no, it's not. Just now an even stranger thing happened. I did a 'composer update' and it replaced my illuminate/html with laravelcollective/html automatically. Oh, strike that, I now see it was just a dependency. – Michiel van der Blonk Jul 12 '15 at 16:38
  • 2
    In laravel 5.1 all of your explanations was correct but in view, `HTML::style` was undefined. But `Html::style` worked. Thanks. – Morteza Oct 03 '15 at 15:51
  • should capitalized the 'Html' to 'HTML' in laravel 5.2 – hahahaha Nov 10 '16 at 08:35
10

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.

Yurii Svystun
  • 101
  • 1
  • 5
  • I fixed with that..'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, – Leoh Feb 06 '16 at 03:46
4

Please change your blade file from this

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

to

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

It's working.

Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57
shijinmon Pallikal
  • 964
  • 11
  • 19
2

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.

manshu
  • 1,095
  • 2
  • 13
  • 28
1

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.

0

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/

channasmcs
  • 1,104
  • 12
  • 27
0

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,
madSkillz
  • 37
  • 1
  • 8
  • I tried all cases, upper case, lower case, title case, you name it. All of them were consistent. None of them worked. After a reinstall _with the same code_ it worked. See my own answer. – Michiel van der Blonk May 29 '16 at 13:08
  • If there was something wrong with the package, when you reinstalled the package would have the same error since the source code hasn't changed. – madSkillz May 31 '16 at 04:13
0

Try it

php artisan cache:clear

php artisan clear-compiled

Community
  • 1
  • 1
Sergey Bogatyrev
  • 93
  • 1
  • 1
  • 5
0

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,
EricZ
  • 1