bewarhizirvan / laravel-form
Laravel 的表单生成器
Requires
- php: ^7.1|^7.4|^8.0|^8.1.0
- illuminate/support: ~5|~6|~7|~8|~9
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3|~4
- phpunit/phpunit: ^8.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-09-24 08:17:51 UTC
README
这里应该放置你的描述。查看 contributing.md 了解待办事项清单。
安装
通过 Composer
$ composer require bewarhizirvan/laravel-form
用法
用于启动新表单
$form = new \BewarHizirvan\LaravelForm\LaravelForm($parameters);
$parameters 必须是数组,是可选的,所有键都是可选的
title : 表单标题
name : 表单名称
method : 表单方法 { get, post (默认), put, patch } class : 表单类
role : 表单角色
dir : 表单方向 { right, left (默认) }
id : 表单 id
file : 如果设置此值,则表单将具有 enctype="multipart/form-data"
submit : 表单提交按钮标题,如果设置为 'none',则将其删除
back_url : 表单返回按钮 URL,如果设置为 'none',则将其删除
对于表单操作,可以使用以下之一(默认为 '')
url : 完整 URL
route : 路由 { 仅路由字符串或数组 Laravel 风格 }
action : 操作 { 仅操作字符串或数组 Laravel 风格 }
函数
$form->addText($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addFile($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addButton($label = '', $attributes = []) $form->addHidden($name = null, $value = '', $attributes = []) $form->addSelect($name= null, $options = [], $value='',$attributes = [],$label=null, $label_attributes = [], $div_attributes = []) $form->addTextArea($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addCheckbox($name = null, $value = 1, $checked = false, $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addCheckboxGroup($name = null, $checkboxes = [], $checked_list = [], $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addRadioGroup($name = null, $radios = [], $checked = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addTable($label = '', $table_data = [], $label_attributes = [], $table_attributes = [], $thead_attributes = [], $tbody_attributes = [], $tfoot_attributes = [], $div_attributes = [])
对于所有函数,如果 $label = null,则函数将设置 $label = trans("db.$name")
对于 addTable 函数 $table_data 将是
$table_data = [ 'names' => [], 'inputs' => [], 'sums' => [], 'buttons' => [], ];
完成后执行以下操作
$form = $form->render();
上述步骤将生成 HTML 代码
示例表单
$form = new \BewarHizirvan\LaravelForm\LaravelForm($parameters); $form->addText('email'); $form->addText('name'); $form->addText('password', '', ['type' => 'password']); $form = $form ->render();
静态函数
\BewarHizirvan\LaravelForm\LaravelForm::redirect($route = '/');
上述函数将检查 $request 中的 back_url,如果已设置,则将其重定向到该 URL,否则将重定向到提供的路由
变更日志
请参阅 changelog 了解最近更改的更多信息。
测试
$ composer test
贡献
请参阅 contributing.md 了解详细信息及待办事项清单。
致谢
许可证
MIT。请参阅 许可证文件 了解更多信息。