'use_dates' => 'required|string|max:3',
'start_date' => 'required_if:use_dates,Yes|date_format:d/m/Y',
'end_date' => 'required_if:use_dates,Yes|date_format:d/m/Y|after:start_date',
$validator = Validator::make($data, [
'start_date' => 'required_if:type,0|date_format:d/m/Y',
], [
'required' => ':attribute必须填写',
], [
'start_date' => '开始时间',
]);
$err = [
'start_date' => '开始时间',
];
if ($validator->fails()) {
$valid_string = '';
foreach ($validator->errors()->messages() as $k => $message) {
if(isset($err[$k])){
$valid_string .= '<br/>' . $err[$k]."必须填写";
}else{
$valid_string .= '<br/>' . $message[0];
}
}
return $this->error([], '验证未通过:'.$valid_string);
}
标签:laravel,use,string,验证,require,required,start,valid,date
From: https://www.cnblogs.com/ianlab/p/17175171.html