1 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以在表單請(qǐng)求中添加后掛鉤,只需覆蓋withValidator如下方法:
/**
* Configure the validator instance.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
public function withValidator($validator)
{
// Check using `sometimes` method
$validator->sometimes("{MenuItem::MENU_ITEM_PRICING}.*.sideprice", 'required', function ($input) {
return $input->${MenuItem::MENU_ITEM_SID};
});
// Or check using `after` method
$validator->after(function ($validator) {
if ($this->input(MenuItem::MENU_ITEM_SID, false)
&& ! \Illuminate\Support\Arr::has($this->input(MenuItem::MENU_ITEM_PRICING, []), '*.sideprice')) {
$validator->errors()->add('field', 'Something is wrong with this field!');
}
});
}
注意:我尚未對(duì)此進(jìn)行全面測(cè)試,但它為您提供了思路。
- 1 回答
- 0 關(guān)注
- 120 瀏覽
添加回答
舉報(bào)