administrcms/form
Composer 安装命令:
composer require administrcms/form
包简介
Form package for the administrcms as good as standalone laravel package
README 文档
README
Work-in-progress.
Installation
- Install using composer:
composer require administrcms/form
- Register the Service Provider (in config/app.php or in app/Providers/AppServiceProvider.php):
// in app.php 'providers' => [ // ... Administr\Form\FormServiceProvider::class, // ... ], // in AppServiceProvider public function register() { $this->app->register(\Administr\Form\FormServiceProvider::class); }
- Publish assets, configs, migrations and etc.
php artisan vendor:publish --provider="Administr\Form\FormServiceProvider"
Creating forms
There is a command available, which will generate a basic scaffold of a Form class for you.
php artisan administr:form MyForm
Or you can just create a new class which extends the Administr\Form\Form class and implement the two abstract methods - rules and form.
Form look and feel
By default the form fields are just basic html, without any styling. When you publish the assets which are connected to the package, the views will be exported to resources/views/vendor/administrcms/form, where you can modify them to adopt the theme of your application.
Usage
The form class needs to be resolved through the IoC container. One way to do that is to type hint the class in the method name.
The forms works like the FormRequests in Laravel, meaning that when you have type hinted the form in the method which responds to the post/put action, it will validate the form and if it is successful then it will execute the code in the method. Otherwise it will return the user back with the errors and populate the form with the user input and display the errors.
<?php namespace App\Http\Controllers; use App\Http\Forms\MyForm; use App\MyModel; class MyController extends Controller { public function create(MyForm $form) { $form->method = 'post'; $form->action = route('my-form-action'); return view('my-view', ['form' => $form]); } public function store(MyForm $form) { MyModel::create($form->request()->all()); } public function edit($id, MyForm $form) { $form->method = 'put'; $form->action = route('my-form-update', [$id]); // The datasource can be an array, Collection or Model $form->dataSource(MyModel::find($id)); return view('my-view', ['form' => $form]); } public function update($id, MyForm $form) { $model = MyModel::find($id); $model->update($form->request()->all()); } }
then in the view you can simply say:
{!! $form->render() !!}
Radio groups
<?php namespace App\Http\Forms; use Administr\Form\Field\RadioGroup; use Administr\Form\Form; use Administr\Form\FormBuilder; class TeamForm extends Form { /** * Define the validation rules for the form. * * @return array */ public function rules() { return [ 'name' => 'required|max:100', ]; } /** * Define the fields of the form. * * @param FormBuilder $form */ public function form(FormBuilder $form) { $form ->text('name', 'Name', ['translated' => true]) ->radioGroup('is_visible', 'Is Visible', function(RadioGroup $group) { $group ->radio('да', ['value' => 1]) ->radio('не', ['value' => 0]); }) ->submit('save', 'Save'); } }
administrcms/form 适用场景与选型建议
administrcms/form 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 515 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 administrcms/form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 administrcms/form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 515
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2016-01-29