【问题标题】:Laravel 5 Class 'HTML' not found未找到 Laravel 5 类“HTML”
【发布时间】:2015-05-05 01:03:30
【问题描述】:

我正在尝试使用 Laravel 5,但我的 {{ HTML::style('style.css') }} 不再有效。

我已更新 composer.json 以在 require 下包含 "illuminate/html": "5.*"。我在 app.php 下的 providers 数组中添加了 'Illuminate\Html\HtmlServiceProvider' 并添加了

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

也是。然后我运行composer update我重新启动了 WAMP 以确保它仍然无法正常工作。我也尝试过使用{!! HTML::style('style.css') !!},但也没有用。我还需要做什么才能找回它?

【问题讨论】:

  • 在编辑composer.json 之后你跑过composer update吗?
  • @manix 是的。我忘了补充,我将编辑问题以包括我也这样做了
  • 删除文件 storage/framework/services.json 以重新生成提供程序并重试
  • @manix 不幸的是什么都没有。
  • 请确认vendor\illuminate\html 文件夹存在

标签: laravel laravel-5


【解决方案1】:
{!! Html::style( asset('public/css/artist.css')) !!}

...对我有用,但是这个

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

... 没用。但它应该工作。不!

Laravel 一天比一天让我困惑。我试着学习这个...... Notwell :D

【讨论】:

  • 看看你的两个代码都区分大小写,你必须注册像'Html'这样的html类,所以第一个有效。这完全是关于如何注册 HTML 类而不计入你如何调用它或打印它。
【解决方案2】:

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

应该是

'Html'=> '照亮\Html\HtmlFacade'

【讨论】:

    【解决方案3】:

    我认为这是一个区分大小写的问题。

    如果在app.php中注册为'HTML'=> 'Illuminate\Html\HtmlFacade',则不能作为html或Html使用(那么只有在使用HTML时才能使用)。

    【讨论】:

      【解决方案4】:
      1. 添加到 composer.json:
        a)“照亮/html”:“5.*”
        b) 运行命令:- composer update

      2. 添加到 app.php 提供程序数组:
        a) 'Illuminate\Html\HtmlServiceProvider',

      3. 添加到 app.php 别名数组:
        a) 'Html' => '照亮\Html\HtmlFacade',
        b) 'Form' => 'Illuminate\Html\FormFacade',

      4. 完成

      【讨论】:

      • 在 5.3 中使用的包是 laravelcollective/html 而不是 illuminate/html
      【解决方案5】:

      如果您不能使用 HTML Facade,为简单起见这样做:

      <link rel="stylesheet" href="{!! asset('style.css') !!}">
      

      【讨论】:

      • 如此轻松地解决了我的问题,我想我们不应该只依靠许多类来完成如此简单的工作。像这样更有价值,因为您不一定知道您的应用程序位于何处(本地、远程服务器)。感谢您的解决方案。
      【解决方案6】:

      app.php 条目应该是:

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

      【讨论】:

        【解决方案7】:

        任何使用 laravel 5.* 的人都必须使用 laravelcollective/html 因为 Package illuminate/html 被废弃了,你应该避免使用它。

        您的composer.json 文件应在require 部分包含以下代码(因为我使用的是laravel 5.2,它将被称为5.2)

        "laravelcollective/html": "5.2.*"
        

        运行composer update

        您的 config/app.php 应该在 providers 数组中包含以下代码

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

        并且别名应该包含

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

        请注意,您提到的任何别名都应在您的代码中显示为

        {{HTML::linkAction('MemberController@show', 'view', array($value->id))}}
        

        【讨论】:

          【解决方案8】:

          对于那些希望使用宏配置 Laravel 5 的人:

          1. composer require laravelcollective/html
          2. 在/config/app.php,"providers" 下:App\Providers\MacroServiceProvider::class
          3. 在/app/Providers下创建MacroServiceProvider.php:

            命名空间 App\Providers;

            使用 Illuminate\Support\ServiceProvider;

            类 MacroServiceProvider 扩展 ServiceProvider {

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

            }

          4. 在文件夹/resources/macros 中添加格式为*.macro.php 的任何宏。请注意所需的$this-&gt;toHtmlString 以转义字符串:

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

            你好

            "); });
          5. 在模板中使用宏,as described here。

          【讨论】:

            【解决方案9】:

            我做了和你一样的事情:在我的作曲家中添加 laravelcollective,作曲家更新,在我的提供者和别名中添加它们,但下面的代码不起作用:

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

            但是,我有这个为我工作

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

            我认为这是因为这个问题是区分大小写的,并且这个 laravel 版本认为 HTML 类与 Html 类完全不同。

            【讨论】:

            • 我也面临这个问题。在一个页面上 HTML 工作,而在另一页面上 Html 工作。它包含与第一页相同的命名空间。为什么会这样?
            【解决方案10】:
            'providers' => [
                 Collective\Html\HtmlServiceProvider::class,
                ]
            
                'aliases' => [
                      'Form' => Collective\Html\FormFacade::class,
                      'Html' => Collective\Html\HtmlFacade::class,
                ]
            

            【讨论】:

            • 这比 BillFromReno 的 answer 或 Shital Jachak 的 answer 好多少?
            【解决方案11】:

            1 关注 https://laravelcollective.com/docs/5.3/html

            首先通过 Composer 安装这个包。从终端运行以下命令:

            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,
                // ...
              ],
            

            最后在config/app.php的aliases数组中添加两个类别名:

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

            现在如果你愿意

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

            或

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

            //2 路跟随。

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

            或

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

            有关更多信息,请参阅此视频教程..... https://www.youtube.com/watch?v=yl6hkoaCS6g

            【讨论】:

              【解决方案12】:

              在 Laravel 5 中 "illuminate/html": "5.*" 已被弃用并替换为新的依赖项 "laravelcollective/html": "~5.0"

              首先通过 Composer 安装这个包。编辑项目的 composer.json 文件以要求“laravelcollective/html”

              在您的 composer.json 文件中更新以下内容:

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

              接下来,从终端更新 Composer:

              composer update
              

              接下来,将你的新提供者添加到 config/app.php 的 providers 数组中:

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

              最后在config/app.php的aliases数组中添加两个类别名:

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

              你也可以在这里查看 Laravel 5

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

              【讨论】:

              • 它有帮助。谢谢
              【解决方案13】:

              按照此文档进行修复:

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

              对于每个版本,您更改版本号以访问相应的文档,例如

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

              x 是版本

              【讨论】:

                【解决方案14】:

                运行这个 cmd 到 laravel 安装的文件夹

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

                和公众一起使用

                {!! Html::style( asset('public/css/artist.css')) !!}
                

                【讨论】:

                  【解决方案15】:

                  使用{{ URL::asset('style.css') }} 代替{{ HTML::style('style.css') }}

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2015-04-16
                    • 2015-07-17
                    • 2015-07-07
                    • 2015-04-29
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2016-10-11
                    相关资源
                    最近更新 更多