1

I am trying to use {{ HTML }} in my project however I am running into several errors. I researched on internet about the problem, and I believe I am doing the right steps, however, I keep falling in the same error while I am trying to load my master page.

FatalErrorException in ... line 9: Class 'HTML' not found

So what I did was:

  • Edited the composer.json file and added "illuminate/html": "5.*" under require {}

  • Run composer update (everything seems fine)

  • Added: providers => 'Illuminate\Html\HtmlServiceProvider', as well as

    `aliasses => 
    'Form'      => 'Illuminate\Html\FormFacade',
    'Html'      => 'Illuminate\Html\HtmlFacade',
    

(Even though the ones already placed under aliasses and providers are as follows which seems the ones I added looks quite different than the rest:

    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    'Illuminate\Html\HtmlServiceProvider', // The one I added

   'URL'       => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View'      => Illuminate\Support\Facades\View::class,
    'Form'      => 'Illuminate\Html\FormFacade', // I added
    'Html'      => 'Illuminate\Html\HtmlFacade', // I added

And here is the snippet version of my master.blade.php:

    <!DOCTYPE html>
    <html lang="en">
    <head>

        <meta charset = "UTF-8">

        <title></title>

        {{ HTML::script('js/jquery.js') }}      // Line 9
        {{ HTML::script('js/bootstrap.js') }}   // Line 10
        {{ HTML::style('css/bootstrap.js') }}   // Line 11

    </head>

The error I am getting is:

FatalErrorException in ### line 9: Class 'HTML' not found in

/Applications/MAMP/htdocs/laratest/storage/framework/views/### line 9


I was benefiting from several tutorials such as This one on YouTube and Laracast. I also found a Solved-tagged question which is addressing the same issue but did not fix the issue in my case.

Edit: Also changing to {!! HTML !!} is not working either

senty
  • 12,385
  • 28
  • 130
  • 260
  • I don't think this is your exact issue, but you alias the facade as `Html` but address it as `HTML`. More importantly (and it still probably won't fix your issue) you should upgrade to the community-led continuation of the illuminate/html package: [laravelcollective/html](https://packagist.org/packages/laravelcollective/html) – alexrussell Jul 20 '15 at 15:41
  • check your case-sensitivity consistency when referencing html/HTML in the code (happened to me, was the fix) – brietsparks Jul 20 '15 at 16:26
  • when I try `{{ Html:.... }}`, I ended up receiving errors: 1) _ErrorException in Manager.php line 137: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'username' (View: /Applications/MAMP/htdocs/laratest/resources/views/master.blade.php)_ 2) _ErrorException in Manager.php line 137: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'username'_ – senty Jul 20 '15 at 16:32
  • As I say, try changing your package to the community-driven one (laravel collective) - the illuminate/html only goes as far as 5.0, so if you're using 5.1 you should upgrade anyway. – alexrussell Jul 20 '15 at 16:47
  • @alexrussell, so what you are suggesting me is removing these 3 rows that I have added in config>app.php (illuminate/html) as well as removing illuminate/html from composer.json; and then composer install laravelcollective/html ? – senty Jul 20 '15 at 16:55
  • Remove `illuminate/html`, since it is deprecated. Do `composer require laravelcollective/html`. Remove your `vendor` folder, do `composer install`. This worked for me when I had the same issue you are having. Also make sure you test it in a route closure, since `Html` or `HTML` can live in layouts and subviews. – user2094178 Jul 20 '15 at 17:53
  • HTML alias in app.php is case sensitive – Gaurav Dave Jul 20 '15 at 18:11
  • @senty yes exactly - user2094178 expands on my advice with somewhat more precise instructions. See docs [here](http://laravelcollective.com/docs/5.1/html) for how to set up the laravelcollective HTML and Form facades. – alexrussell Jul 21 '15 at 08:06

5 Answers5

3

Illuminate/HTML package has been deprecated

Use:laravelcollective/html

composer require laravelcollective/html

Add this lines in config/app.php

in providers group:

Collective\Html\HtmlServiceProvider::class,

in aliases group:

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
Kyizin
  • 371
  • 4
  • 16
1

First the facades aren't correct.

'Form'      => 'Illuminate\Html\FormFacade', // FormFacade not HtmlFacade
'Html'      => 'Illuminate\Html\HtmlFacade',

The facade is Html not HTML.

<!-- This won't work -->
{!! HTML::script('js/jquery.js') !!}

<!-- This should work -->
{!! Html::script('js/jquery.js') !!}

Or you could change the facade key to HTML and then you can use HTML::script(...).

'HTML'      => 'Illuminate\Html\HtmlFacade'
David Barker
  • 14,484
  • 3
  • 48
  • 77
  • I corrected everything as you showed. However, this time, I ran into bunch of errors under 2 headings.. **1)** _ErrorException in Manager.php line 137: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'username'_ **2)** _ErrorException in Manager.php line 137: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'username' (View: /Applications/MAMP/htdocs/laratest/resources/views/master.blade.php)_ – senty Jul 20 '15 at 16:49
  • In the blade template do you have something like this: `Auth::username()`? – David Barker Jul 20 '15 at 18:04
0

In migrating to 5.1 I found the same issue - it appears as though the HTML class no longer supports the script and style methods.

Instead, use:

{{ URL::asset('yourassetpath') }}
BrynJ
  • 8,322
  • 14
  • 65
  • 89
0

Try this:

{!! HTML !!}

and, don't forgot to composer dumpautoload.

See, if that helps.

Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
  • Yes, I tried that `{!! HTML !!} ` . Just edited the OP. Sorry for writing `{!! HTML !}}`. – senty Jul 20 '15 at 16:27
0

you are using two different aliases to the same facade. the correct facades are

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

this should work

p.s. as of laravel 5.1 you should use facadeName::class

Eli Y
  • 877
  • 16
  • 41
  • He tried this: {!! HTML !}} which is wrong. Look closely. – Gaurav Dave Jul 20 '15 at 15:50
  • @GauravDave, @elibyy. I tried {!! HTML !!}. I'm sorry for the misclick on OP. I just edited it.. Also I now tried: `'Form' => Illuminate\Html\HtmlFacade::class,` `'Html' => Illuminate\Html\HtmlFacade::class, ` as you said, but still the same error. – senty Jul 20 '15 at 16:24
  • notice I've written Html and not HTML try to change between them because AFAIK it's case sensitive – Eli Y Jul 20 '15 at 17:13