目前,我在Laravel项目中有这个(有效的)验证器
$validator = Validator::make(
$insert_data1,
[
'*.emp_id' => "required|exists:users,company_id",
],
[
'*.emp_id.exists' => 'The selected :attribute is invalid. Employee does not exists!',
]
);
if($validator->fails()){
return redirect()
->back()
->with(['errors'=>$validator->errors()->all()])
->with('modal',$modal);
}
现在我需要为像这样的其他变量添加另一个验证
$insert_data2,
[
'*.emp_id' => "required|exists:users,company_id",
],
[
'*.emp_id.exists' => 'The selected :attribute is invalid. Stakeholder does not exists!',
]
如何添加$ insert_data2inside of the
validator`?
您需要做这样的事情
$validation = array(
'name' => 'required|max:60',
'email' => 'required|email',
// N Number of validation Rules
);
$messages = array(
'name.required' => 'A Name is required',
'name.max' => 'Name can only be of max 60 alphanumerics',
'email.required' => 'Email address is required',
'email.email' =>'Email must be a valid email'
// N number of validation messages
);
$response = Validator::make($request,$validation,$messages);
if($response->fails()){
//Your Logic
}