我想自定义我的Laravel验证器。
截至目前,我有多个复选框
<input type="checkbox" name="prodRelatedID[]" value="1">
<input type="checkbox" name="prodRelatedID[]" value="5">
<input type="checkbox" name="prodRelatedID[]" value="189">
and in my Request.php
file I have this
public function rules()
{
return [
'prodTitle' => ['required', 'string', 'max:255'],
'prodDesc' => ['required', 'string', 'max:255'],
'attachment' => ['image','mimes:jpeg,png,jpg,gif,svg','max:2048'],
'prodSize' => ['required','string','max:255'],
'prodCategory' => ['required','string','max:255'],
'prodPrice' => ['required','regex:/^\d*(\.\d{1,2})?$/'],
'prodRelatedID' => ['required'],
'prodRelatedID.*' => ['accepted'],
];
}
Now how can I customize the error message like for the prodRelatedID
?
如果用户未选中复选框,则将返回如下内容
Please choose atleast 1 product related
如果您使用表单请求,则可以覆盖messages方法: