找不到 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
Laravel 5 Class 'HTML' not found
提问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 update
I 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/html
because Package illuminate/html
is abandoned, you should avoid using it.
任何使用 laravel 5.* 的人都必须使用,laravelcollective/html
因为 Packageilluminate/html
被放弃了,你应该避免使用它。
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)
您的composer.json
文件应在 require 部分包含以下代码(因为我使用的是 laravel 5.2,因此将被称为 5.2)
"laravelcollective/html": "5.2.*"
run composer update
跑 composer update
and your config/app.php
should 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
Add to composer.json:
a) "illuminate/html": "5.*"
b) Run Command:- composer updateAdd to the app.php providers array:
a) 'Illuminate\Html\HtmlServiceProvider',Add to the app.php aliases array:
a) 'Html' => 'Illuminate\Html\HtmlFacade',
b) 'Form' => 'Illuminate\Html\FormFacade',Done
添加到 composer.json:
a) "illuminate/html": "5.*"
b) 运行命令:- composer update添加到 app.php providers 数组:
a) 'Illuminate\Html\HtmlServiceProvider',添加到 app.php 别名数组:
a) 'Html' => 'Illuminate\Html\HtmlFacade',
b) 'Form' => 'Illuminate\Html\FormFacade',完毕
回答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
回答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 的人:
composer require laravelcollective/html
- In
/config/app.php
, under"providers"
:App\Providers\MacroServiceProvider::class
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() { // }
}
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
"); });Use macros in templates, as described here.
composer require laravelcollective/html
- 在
/config/app.php
,在"providers"
:App\Providers\MacroServiceProvider::class
创建
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() { // }
}
在文件夹
/resources/macros
中以格式添加任何宏*.macro.php
。请注意需要$this->toHtmlString
以转义字符串:Html::macro("something", function() { return $this->toHtmlString("
你好呀
"); });如此处所述,在模板中使用宏。