Laravel5生成html,css和表单

1.首先安装依赖库

composer require illuminate/html

2.注册HtmlServiceProvider

在 config/app.php 中的providers 字段的最后添加:

Illuminate\Html\HtmlServiceProvider::class,

3.添加别名

不希望使用 Illuminate\Html\FromFacade 这么长的名字来引入,我们需要简短的名字。在当前的 app.php 中找到 aliases 段,在最后添加别名。

'Form'      => Illuminate\Html\FormFacade::class,
'Html'      => Illuminate\Html\HtmlFacade::class,

4.使用方法

在blade模板引擎的视图中这样使用:

{!! Html::style('/assets/css/style.css') !!}
{!! Html::script('js/jquery.js') !!}
{!! Form::open(['url' => 'articles']) !!}
{!! Form::close() !!}

发表评论

邮箱地址不会被公开。 必填项已用*标注

返回顶部