[英]how can I use both required_if and required_without for validation in laravel?
I want to make validation this: body.*.image.file
is required when value of body.*.type
is left or right and body.*.image.saved
is empty .我想这样验证:
body.*.image.file
is required when body.*.type
is left or right and body.*.image.saved
is empty 。
I tried this:我试过这个:
$validator = Validator::make($input, [
'body' => 'required|array',
'body.*.type' => 'required|in:left,right,center',
'body.*.image.saved' => 'nullable|json',
'body.*.image.file' => 'required_if:body.*.type,left,right|required_without:body.*.image.saved',
]);
but it returns wrong result.但它返回错误的结果。
'body.*.image.file' => Rule::requiredIf(function () use ($request) {
return ($request->input('body.*.type') == left || $request->input('body.*.type') == right) && empty($request->body.*.image.saved);
}),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.