ifnot / validation-parser
此包已被弃用且不再维护。未建议替代包。
关于此包的最新版本(0.4.2.1)没有可用的许可证信息。
0.4.2.1
2016-04-27 10:11 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.*
Requires (Dev)
- orchestra/testbench: 2.2.*
This package is auto-updated.
Last update: 2020-02-05 23:05:00 UTC
README
用于从简单的 Laravel 验证数组自动生成表单、自动生成文档等功能的 Laravel 验证规则解析器。
兼容 Laravel 4 和 Laravel 5
安装
composer require "ifnot/validation-parser"
自定义使用
在本例中,我们将使用自定义视图调用 RuleSet 解析器以渲染自动表单。
在控制器动作/路由中,我们定义每个字段使用的视图
Ifnot\ValidationParser\RuleSet::$view = 'my.form.field'; return View::make('my.form.show');
在 /view/my/form/show.blade.php
中,我们遍历每个 RuleSets 并将属性绑定到 RuleSet 视图。
@foreach([ "email":"required|email", "civility":"required|in:M,F", "comment":"string" ] as $property => $rules) {{ \Ifnot\ValidationParser\RuleSet::parse($rules)->bind('property' => $property)->toString() }} @endforeach
在 RuleSet 视图 /views/my/form/field.blade.php
(之前指定)中
<label>{{ $property }}</label> @if($ruleSet->isBoolean()) {{-- Here insert a input type radio --}} @elseif($ruleSet->isIn()) {{-- Here, you can insert a select with $ruleSet['in']->params witch contains an array of allowed values --}} @elseif($field->isExists()) {{-- Here a ajax loaded json from your table $ruleSet['in']->params[0] and the column $ruleSet['in']->params[1] --}} @endif