luthfi / formfield
Laravel 表单字段扩展,为 Laravel 5.3 及更高版本提供基于 Twitter Bootstrap 4 的表单字段包装。
3.1.0
2024-08-13 15:22 UTC
Requires
- php: ^8.1
- konekt/html: ^6.5
Requires (Dev)
- orchestra/testbench: ^9.0
- dev-master
- 3.1.0
- 3.0.1
- 3.0.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-text_steps
- dev-bugfix_missing_checkbox_validation_messages
This package is auto-updated.
Last update: 2024-09-13 16:04:08 UTC
README
本包是对 Laravelcollective Form 的扩展,支持 Laravel 5 及更高版本,并提供基于 Twitter Bootstrap 3、4 和 5 的表单字段包装。
安装方法
对于 Bootstrap 5
如果您使用 Bootstrap 5,请使用 3.*
版本代替
composer require luthfi/formfield 3.*
对于 Bootstrap 4
如果您使用 Bootstrap 4,请使用 2.*
版本代替
composer require luthfi/formfield 2.*
对于 Bootstrap 3
如果您使用 Bootstrap 3,请使用 1.*
版本代替
composer require luthfi/formfield 1.*
通过 Composer 安装此包。请在终端运行以下命令
composer require luthfi/formfield
对于 Laravel 5.5 及更高版本
此包将自动发现
对于 Laravel 5.3 和 5.4
更新 config/app.php
,添加提供者和别名
// providers Luthfi\FormField\FormFieldServiceProvider::class, // aliases 'FormField' => Luthfi\FormField\FormFieldFacade::class, 'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class,
使用方法
在您的 blade
文件中,使用以下语法
{!! FormField::text('name') !!}
将生成
<div class="form-group "> <label for="name" class="control-label">Name</label> <input class="form-control" name="name" id="name" type="text"> </div>
或用于复选框和单选按钮的其它示例。我们可以使用 数字数组 或 关联数组 来表示标签和值
{!! FormField::checkboxes('group', [1 => 'Admin', 'Member']) !!} {!! FormField::radios('status', ['a' => 'Active', 'b' => 'Inactive']) !!}
它们将生成
<!-- Checkboxes --> <div class="form-group "> <label for="group" class="control-label">Group</label> <div> <div class="form-check form-check-inline"> <input id="group_1" class="form-check-input" name="group[]" value="1" type="checkbox"> <label for="group_1" class="form-check-label">Admin</label> </div> <div class="form-check form-check-inline"> <input id="group_2" class="form-check-input" name="group[]" value="2" type="checkbox"> <label for="group_2" class="form-check-label">Member</label> </div> </div> </div> <!-- Radios --> <div class="form-group "> <label for="status" class="control-label">Status</label> <div> <div class="form-check form-check-inline"> <input id="status_a" class="form-check-input" name="status" value="a" type="radio"> <label for="status_a" class="form-check-label">Active</label> </div> <div class="form-check form-check-inline"> <input id="status_b" class="form-check-input" name="status" value="b" type="radio"> <label for="status_b" class="form-check-label">Inactive</label> </div> </div> </div>
可用的表单字段
{!! FormField::open($options) !!} {!! FormField::text('name') !!} {!! FormField::textarea('field_name') !!} {!! FormField::select('field_name', $options) !!} {!! FormField::multiSelect('field_name', $options) !!} {!! FormField::email('email_field') !!} {!! FormField::password('password_field') !!} {!! FormField::radios('status', ['a' => 'Active', 'b' => 'Inactive']) !!} {!! FormField::checkboxes('group', [1 => 'Admin', 'Member']) !!} {!! FormField::textDisplay('label', 'value_to_display') !!} {!! FormField::file('file_field') !!} {!! FormField::price('price_field') !!} {!! FormField::close() !!}