Laravel 5 Class 'HTML' not found

前端 未结 14 1581
野性不改
野性不改 2020-12-10 01:03

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

I have updated composer.json to include \"illuminate/ht

相关标签:
14条回答
  • 2020-12-10 01:23

    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.

    0 讨论(0)
  • 2020-12-10 01:25

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

    <link rel="stylesheet" href="{!! asset('style.css') !!}">
    
    0 讨论(0)
  • 2020-12-10 01:25

    the app.php entries should be:

    'providers' => [
    
        // ...
        Collective\Html\HtmlServiceProvider::class,
        // ...
    ],
    
    'aliases' => [
    
        // ...
        'Form' => Collective\Html\FormFacade::class,
        'Html' => Collective\Html\HtmlFacade::class,
        // ...
    ],
    
    0 讨论(0)
  • 2020-12-10 01:27

    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

    0 讨论(0)
  • 2020-12-10 01:28

    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.

    0 讨论(0)
  • 2020-12-10 01:31
    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

    0 讨论(0)
提交回复
热议问题