vaneeves/laravel-form

Laravel 框架的 HTML 辅助工具

dev-master 2017-12-01 18:10 UTC

This package is auto-updated.

Last update: 2024-09-19 10:01:16 UTC


README

使用 Composer 安装

composer require vaneves/laravel-form

配置

Form 门面添加到 config/app.php 中的 aliases 数组

'aliases' => [
    //...
    'Form' => Vaneves\Laravel\Form\Form::class,
]

用法

基本

{!! Form::open('register') !!}
  {!! Form::text('Your name', 'name') !!}
  {!! Form::email('Email', 'email') !!}
  {!! Form::password('Password', 'password') !!}
  {!! Form::reset('Clear')->warning() !!}
  {!! Form::submit('Save')->primary() !!}
{!! Form::close() !!}

表单方法

open([string $action])

close()

action($path)

method($name)

  • get()
  • post()
  • put()
  • patch()
  • delete()

horizontal([array $sizes])

inline()

required()

placeholder()

hideLabel()

lg()

sm()

字段类型

字段方法

required()

在字段中添加属性 required

optional()

从字段中移除属性 required

lg()

在字段中添加类 input-lg

sm()

在字段中添加类 input-sm

attr(string $name [, string $value])

在元素中添加具有 data 的属性。示例

{!! Form::text('Your Name', 'name')->attr('my-prop', 'value') !!}

输出

<div class="form-group">
  <label for="name">Your Name</label>
  <input type="text" class="form-control" id="name" my-prop="value">
</div>

removeAttr(string $name)

从元素中移除属性。

data(string $name [, string $value])

在元素中添加具有 data 的属性。示例

{!! Form::text('Your Name', 'name')->data('my-prop', 'value') !!}

输出

<div class="form-group">
  <label for="name">Your Name</label>
  <input type="text" class="form-control" id="name" data-my-prop="value">
</div>

addClass(string $name)

在元素中添加类。示例

{!! Form::text('Your Name', 'name')->addClass('material-design') !!}

输出

<div class="form-group">
  <label for="name">Your Name</label>
  <input type="text" class="form-control material-design" id="name">
</div>

removeClass(string $name)

从元素中移除类。