找不到 Laravel 5 类“HTML”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28847726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:54:36  来源:igfitidea点击:

Laravel 5 Class 'HTML' not found

laravellaravel-5

提问by Michael N

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

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

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

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

'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?

以及。然后我运行composer update我已经重新启动 WAMP 以确保它仍然不起作用。我也尝试使用 {!! HTML::style('style.css') !!}which 也不起作用。我还需要做什么才能恢复它?

回答by Shital Jachak

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

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

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

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

"laravelcollective/html": "5.2.*"

run composer update

composer update

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

并且您config/app.php应该在提供者数组中包含以下代码

'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))}}

回答by rick mills

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

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

should be

应该

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

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

回答by sunny kashyap

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).

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

回答by Yettie

{!! 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

Laravel 每天都让我更加困惑。我试着学习这个...... Notwell :D

回答by Al-mahbub Khan

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

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

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

首先通过 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,
    // ...
  ],

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

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

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

Now if you want

现在如果你想要

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

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

or

或者

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

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

//2 way follow.

//2 路跟随。

    {{ 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

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

回答by Ankit Tyagi

  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

  1. 添加到 composer.json:
    a) "illuminate/html": "5.*"
    b) 运行命令:- composer update

  2. 添加到 app.php providers 数组:
    a) 'Illuminate\Html\HtmlServiceProvider',

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

  4. 完毕

回答by Sagar Arora

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

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

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

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

In your composer.json file update the following:

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

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

Next, update Composer from the Terminal:

接下来,从终端更新 Composer:

composer update

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

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

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

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

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

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

You can also check it here for Laravel 5

你也可以在这里查看 Laravel 5

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

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

回答by Fred Ondieki

Follow this documentation how to fix it:

按照此文档如何修复它

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

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

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

x is the version

x 是版本

回答by Emeka Mbah

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

如果您不能使用 HTML Facade,为了简单起见,请执行以下操作:

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

回答by user1429980

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

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

  1. composer require laravelcollective/html
  2. In /config/app.php, under "providers": App\Providers\MacroServiceProvider::class
  3. Create MacroServiceProvider.phpunder /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/macrosin the format *.macro.php. Note the needed $this->toHtmlStringin order to escape the string:

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

    Hi there

    "); });

  5. Use macros in templates, as described here.

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

    命名空间 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->toHtmlString以转义字符串:

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

    你好呀

    "); });

  5. 如此处所述,在模板中使用宏。