【发布时间】:2018-05-05 07:05:04
【问题描述】:
我正在开发一个管理员面板,管理员可以在其中为会员申请设置验证自定义验证规则。我知道需要在数据库中设置一个 $attribute => $rules 对。
但是,有一个请求的功能我不太确定如何实现。管理员希望每个 $key => $rule 对递归地并且可选地具有子级 $key => $rule 对,如果父级失败,将执行这些子级。所以最后,每个规则可能有 0 到多个子规则,这些子规则都需要通过才能使父规则通过。
例子:
// Original validation (Assume age = 16, time_at_job = 18 and monthly_income = 3000)
[
'age' => 'min:21', // Fail, but pass because of subset is all pass
'time_at_job' => 'min:6' // Pass
'monthly_income' => 'min:2000' // Pass
]
// If the original age fails and this passes, then age passes and continue to the original
time_at_job.
[
'age' => 'min:18, // Fail, but pass because of subset is all pass
'time_at_job' => 'min:12' // Pass
'monthly_income' => 'min:2500' // Pass
]
// If the subset age passed and this passes, then the subset age passes, but the subset
time_at_job and monthly income will need to pass before the original age can pass.
[
'age' => 'min:16, // Pass
'time_at_job' => 'min:18' // Pass
'monthly_income' => 'min:3000' // Pass
]
任何关于从哪里开始的帮助将不胜感激。
【问题讨论】:
标签: php laravel validation recursion laravel-5