Laravel 5 and Illuminate/html

2019-02-28 04:38发布

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

5条回答
▲ chillily
2楼-- · 2019-02-28 05:00

Try this:

{!! HTML !!}

and, don't forgot to composer dumpautoload.

See, if that helps.

查看更多
小情绪 Triste *
3楼-- · 2019-02-28 05:06

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,
查看更多
甜甜的少女心
4楼-- · 2019-02-28 05:13

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

查看更多
一纸荒年 Trace。
5楼-- · 2019-02-28 05:15

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'
查看更多
来,给爷笑一个
6楼-- · 2019-02-28 05:17

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') }}
查看更多
登录 后发表回答