rashidhamidov/model-form
Composer 安装命令:
composer require rashidhamidov/model-form
包简介
Dynamic Model Form for crate form automaticaly from model fields
README 文档
README
This is package is for create dynamic crud forms for model.
- Laravel 8 is supported
composer require rashidhamidov/model-form
These advantages are
- Create Dynamic Forms from Model file with one function
- Create Rules in Model file with one function
- Automatically Creates Forms which you want
- You can change the class names and can add more than one class name into form element
Inserting Trait to Model
class Product extends Model { use HasCrudForm; }
Abstract Functions
setRootName() and setRules() is a mandatory functions for models that extends HasCrudForm trait
You have to override this functions for form post and request validation. If you set root name as product the form action will be route with names:
- product.store
- product.update
It automatically gets the model data id from your send with form function
private function setRootName() { return "product"; } private function setRulesStore() { return [ 'name'=>"required" ]; } private function setRulesUpdate() { return [ 'name'=>"required" ]; }
Make Form Fields
There is a function for create form formFields() and returns an array. You can create form like this.
protected function formFields() { return [ "name" => $this->setInputField('name', 'text', 'form-control', true, ''), "gender" => $this->setInputField('gender', 'radio', 'form-control', true, '', ["Male" => 'male', "Female" => "female"]), "phone" => $this->setInputField('phone', 'text', 'form-control phone-mask', false, ''), "detail" => $this->setTextAreaField('detail', 'form-control richtext', false, ''), "status" => $this->setSelectField('status', 'form-control', true, '', ['True'=>1, 'False'=>0]), "user" => $this->setForeignField('id','email','user_id', 'form-control', true, '', User::all()->toArray()), "date" => $this->setInputField('date', 'date', 'form-control', false, ''), "time" => $this->setInputField('time', 'time', 'form-control', false, ''), ]; }
There are three type of elements and full type of those elements in form. You can also set className into array and required fields. In select filed you have to set array into array that values in it.
Call Form Function
$model = new Product();
Into your blade file form() function returns a views that comprise form of Model.
{{$model->form()}}
For Model Update Form you have to send model as variable which you want to change.
$model = Product::find($id); $model->form($model);
Before use form() function you have to define in your web.php file Model Controller Route resource or store and update routes for store and update routes
Route::resource('product',ProductController::class); //or Route::post('/product',[ProductController::class,'store'])->name('product.store') Route::put('/product/{product}',[ProductController::class,'update'])->name('product.store')
Rules Usage
After define rules you can use validation with this rule array
public function store(Request $request) { $model = new Product(); $request->validate($model->getRules()); }
License
This package is developed by Rashid Hamidov for Laravel framework MIT license.
rashidhamidov/model-form 适用场景与选型建议
rashidhamidov/model-form 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「dynamic-form」 「model-form」 「form-rule」 「crud-form」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rashidhamidov/model-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rashidhamidov/model-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rashidhamidov/model-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-17