30

I am attempting to use Laravel 5 but my {{ HTML::style('style.css') }} No longer works.

I have updated composer.json to include "illuminate/html": "5.*" under require. I have added 'Illuminate\Html\HtmlServiceProvider' to my providers array under app.php and I have added

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

as well. I then ran composer updateI have restarted WAMP to make sure and it still does not work. I have also tried to use {!! HTML::style('style.css') !!} which did not work either. What else do I need to do to get this back?

15 Answers15

26

Anybody who are using laravel 5.* have to use laravelcollective/html because Package illuminate/html is abandoned, you should avoid using it.

your composer.json file should contain following code in require section(as i am using laravel 5.2 it will be mentioned as 5.2)

"laravelcollective/html": "5.2.*"

run composer update

and your config/app.php should contain following code in providers array

'providers' => [
                       Collective\Html\HtmlServiceProvider::class,

]

and aliases should contain

'aliases' => [

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

and please note that whatever aliase you mentioned should appear in your code as

{{HTML::linkAction('MemberController@show', 'view', array($value->id))}}
Shital Jachak
  • 449
  • 6
  • 14
16

'HTML'=> 'Illuminate\Html\HtmlFacade'

should be

'Html'=> 'Illuminate\Html\HtmlFacade'

rick mills
  • 177
  • 4
10

I think it's a case sensitive problem.

If you register it as 'HTML'=> 'Illuminate\Html\HtmlFacade' in app.php, you can't use it as html or Html ( then it will only work when you use HTML).

sunny kashyap
  • 2,193
  • 2
  • 19
  • 29
9
{!! Html::style( asset('public/css/artist.css')) !!}

... worked for me, but this

{{ HTML::style( asset('css/artist.css')) }}

... did not worked. But it should work. No!

Laravel is confusing me more from day to day. I try to learn this ... Notwell :D

Yettie
  • 91
  • 3
  • 1
    See there is case sensitivity in your both code you have must registered html class like 'Html' so first one works. It's all about how registered HTML class no meter how you call it or print it. – sunny kashyap Jun 27 '16 at 08:39
8

1 follow https://laravelcollective.com/docs/5.3/html

Begin by installing this package through Composer. Run the following from the terminal:

composer require "laravelcollective/html":"^5.3.0"
Next, add your new provider to the providers array of config/app.php:

  'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

Finally, add two class aliases to the aliases array of config/app.php:

  'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],

Now if you want

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

or

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

//2 way follow.

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

    //change to 

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

or

    'aliases' => [
            // ...
              'Form' => Collective\Html\FormFacade::class,
              'Html' => Collective\Html\HtmlFacade::class,
            // ...
          ],

    //change to 

    'aliases' => [
            // ...
              'Form' => Collective\Html\FormFacade::class,
              'HTML' => Collective\Html\HtmlFacade::class,
            // ...
          ],

for more see this video tutorial..... https://www.youtube.com/watch?v=yl6hkoaCS6g

Al-mahbub Khan
  • 309
  • 2
  • 10
7
  1. Add to composer.json:
    a) "illuminate/html": "5.*"
    b) Run Command:- composer update

  2. Add to the app.php providers array:
    a) 'Illuminate\Html\HtmlServiceProvider',

  3. Add to the app.php aliases array:
    a) 'Html' => 'Illuminate\Html\HtmlFacade',
    b) 'Form' => 'Illuminate\Html\FormFacade',

  4. Done

Ankit Tyagi
  • 199
  • 2
  • 3
4

In the Laravel 5 "illuminate/html": "5.*" is deprecated and replaced with new dependency "laravelcollective/html": "~5.0"

Begin by installing this package through Composer. Edit your project's composer.json file to require "laravelcollective/html"

In your composer.json file update the following:

"require": {
   "laravelcollective/html": "~5.0"
}

Next, update Composer from the Terminal:

composer update

Next, add your new provider to the providers array of config/app.php:

'providers' => [
 // ...
 'Collective\Html\HtmlServiceProvider',
 // ...
],

Finally, add two class aliases to the aliases array of config/app.php:

'aliases' => [
 // ...
   'Form' => 'Collective\Html\FormFacade',
   'Html' => 'Collective\Html\HtmlFacade',
 // ...
],

You can also check it here for Laravel 5

https://laravelcollective.com/docs/5.0/html

Sagar Arora
  • 1,743
  • 1
  • 10
  • 19
1

If you must not use HTML Facade, do this for simplicity:

<link rel="stylesheet" href="{!! asset('style.css') !!}">
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96
  • 1
    Solved my issue so easily, I guess we should not rely only on many classes to do such a simple work. It is way more valuable like this because you don't necessarily know where your app is located (local, remote server). Thank you for the solution. – Anwar Apr 12 '16 at 15:25
1

Follow this documentation how to fix it:

https://laravelcollective.com/docs/5.4/html

For each version you change the version number to access the appropriate doc e.g

https://laravelcollective.com/docs/5.x/html

x is the version

Fred Ondieki
  • 2,314
  • 25
  • 23
0

For those who are looking to configure Laravel 5 with macros:

  1. composer require laravelcollective/html
  2. In /config/app.php, under "providers": App\Providers\MacroServiceProvider::class
  3. Create MacroServiceProvider.php under /app/Providers:

    namespace App\Providers;

    use Illuminate\Support\ServiceProvider;

    class MacroServiceProvider extends ServiceProvider {

    public function boot()
    {
        foreach (glob(base_path("resources/macros/*.macro.php")) as $filename) {
            require_once($filename);
        }
    }
    
    public function register()
    {
        //
    }
    

    }

  4. Add any macros in the folder /resources/macros in the format *.macro.php. Note the needed $this->toHtmlString in order to escape the string:

    Html::macro("something", function() { return $this->toHtmlString("

    Hi there

    "); });
  5. Use macros in templates, as described here.

user1429980
  • 6,872
  • 2
  • 43
  • 53
0

run this cmd to laravel installed folder

composer require "laravelcollective/html":"^5.4.0"

and use with public

{!! Html::style( asset('public/css/artist.css')) !!}
Anjani Barnwal
  • 1,362
  • 1
  • 17
  • 23
0

Use {{ URL::asset('style.css') }} instead of {{ HTML::style('style.css') }}

Brahimaito
  • 55
  • 4
-1

the app.php entries should be:

'providers' => [

    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
],

'aliases' => [

    // ...
    'Form' => Collective\Html\FormFacade::class,
    'Html' => Collective\Html\HtmlFacade::class,
    // ...
],
YakovL
  • 7,557
  • 12
  • 62
  • 102
-1

I did the same thing as you did: added laravelcollective in my composer, did composer update, added them in my providers and aliases but the code below did not work:

{{ HTML::image('img/picture.jpg') }}

However, I have this working for me

{{ Html::image('img/picture.jpg') }}

I think this is because this issue is case sensitive and that the class HTML vs class Html is being seen as entirely different from one another by this laravel version.

Charmie
  • 2,468
  • 7
  • 33
  • 47
  • I also face this issue. On one page HTML works and on other page Html works. It includes the same namespaces as first page.Why is that? – vivek321 Feb 25 '17 at 18:56
-2
'providers' => [
     Collective\Html\HtmlServiceProvider::class,
    ]

    'aliases' => [
          'Form' => Collective\Html\FormFacade::class,
          'Html' => Collective\Html\HtmlFacade::class,
    ]
Parth Vora
  • 4,073
  • 7
  • 36
  • 59
  • 1
    How is this any better than BillFromReno's [answer](http://stackoverflow.com/a/38819082/369450) or Shital Jachak's [answer](http://stackoverflow.com/a/39079405/369450)? – Uyghur Lives Matter Dec 07 '16 at 19:52