kregel/formmodel
最新稳定版本:v2.3.16
Composer 安装命令:
composer require kregel/formmodel
包简介
A quick way to make forms for your Laravel models
README 文档
README
Config file
/* * @param String * @return Collection */ 'resolved_relationship' => function ($class_name) { return $class_name::limit(15)->get(); },
What this code does, is, if there is a relationship, but it will return the resolved relationship function's evaluation. So if you want to scope this down some, then be my guest.
Custom frameworks.
The next step is to change the way your framework interacts with the modelInput method. There is a new "base" framework impementation, which draws from something only some classes had which is the automatic relationship resolution. If you extend the Plain framework then you will be able to use this feature by default. Other wise you can keep doing what you're doing :)
If you need custom attributes on your form inputs like v-models (for vue) or some other javascript framework or you want to add custom classes, It's recommended that your framework only contain methods that relate to the inputs for that framework, and to not have them override the default modelInputs method
Oh crap! an update broke my App!! WHAT DO I DOOO!? FIX IT NOW!!
Please, before you raise a lynch mob on Twitter, use your brain and the wonderful human powers of deductive reasoning.
So, as of 2.0, there was a huge structure change with... Well, everything. I made the whole system a bit more modular and extensible. So instead of needing to create a new instance of your model AND FormModel, now you just need to new up a FormModel instance. Or... If you have our facade set up, you can use the facade.
What is this package?
This package was created to help decrease the time it takes to echo out a form relating to a given Model while still giving the developer the ultimate amount of flexibility .
What do I need to do to make it work?
To get it to work properly, similar to how it works in my Warden package, it's recommended to do the following
-
composer require kregel/formmodel or add
"kregel/formmodel":"^2.0"to your composer.json file, just be sure to usecomposer updatewith that statement, or if you haven't build your dependancies usecomposer installinstead. -
Register the service provider with your
config/app.phpfile
'providers' => [ ..., Kregel\FormModel\FormModelServiceProvider::class, ..., ]
- (optional) Add the alias to your
config/app.phpfile
'aliases' => [ ..., 'FormModel' => Kregel\FormModel\Facades\FormModel::class, ..., ]
- Publish the config file! This should be able to be done with
php artisan vendor:publish - Use your favorite way to new up a FormModel, this can be done using the Facade or by just doing
$form = new Kregel\FormModel\FormModel;
- Use something similar to the following in your controller, or in your view (maybe you injected it?)
$form->using(config('kregel.formmodel.using.framework')) ->withModel($model) ->submitTo(route('warden::api.create-model')) ->form([ 'method' => 'post', 'enctype' =>'multipart/form-data' ]);
- Print the results!
Do you have an example?
Duhh! Let it be known that this is a method in one of the controllers from my Warden package.
protected function getNewModel($model_name, FormModel $form) { /* * We need to grab the model from the config and select one entry for * that model from within the database. */ $model = $this->findModel($model_name); /* * Here we generate the form to update the model using the kregel/formmodel * package */ $form_info = $form->using(config('kregel.formmodel.using.framework')) ->withModel($model) ->submitTo(route('warden::api.create-model')) ->form([ 'method' => 'post', 'enctype' =>'multipart/form-data' ]); return view('warden::view-model') ->with('form', $form_info) ->with('model_name', $model_name); }
Extending
You can extend this system just like you would with my Menu Package. In the section in the config labeled 'custom-framework'. Modify the Namespacing of the newed up object to your class and it should just work (assuming you knew to use the structure of the class below)
<?php namespace App\FormModel\Frameworks; use Kregel\FormModel\Interfaces\FrameworkInputs; use Kregel\FormModel\Interfaces\FrameworkInterface; class MyFramework extends FrameworkInputs implements FrameworkInterface { // The only method that you NEED is the form function public function form(Array $options = []){ // Do Stuff (build the form) $method = empty($options['method']) ? $options['method'] : ''; if (in_array(strtolower($method), ['get', 'post'])) { $real_method = $method; } else { $real_method = 'POST'; } $options['method'] = $real_method; $options['action'] = $this->location; return '<form ' . $this->attributes($options) . '>' . // Pass the method through so the form knows how to handle it's self (with laravel) $this->method($method) . // Check and fill the csrf token if it's configured for it. $this->csrf() . $this->buildForm() . $this->submit([]) . '</form>'; } }
Questions?
Email me (my email is on my github page), or you can drop an issue. :)
kregel/formmodel 适用场景与选型建议
kregel/formmodel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 878 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「crud」 「laravel」 「form-generation」 「html」 「vue-js」 「vuejs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kregel/formmodel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kregel/formmodel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kregel/formmodel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Gii Generator for double model generation
A PSR-7 compatible library for making CRUD API endpoints
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
Collection of tools to use the full power of the Enyalius framework
Laravel Admin CRUD Generator
Alfabank REST API integration
统计信息
- 总下载量: 878
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-10-01