您可以使用javascript将日期设置到另一个隐藏字段中,如果其他字段已填充,则可以像以前一样验证该字段。或者,如果您不想使用javascript,您可以在if语句中对当前日期输入进行额外检查,并更改它们的规则以适应或抛出异常
public function rules()
{
$rules = [
'firstnames' => 'required',
'lastname' => 'required',
'dob_day' => ['digits_between:1,2', 'nullable', 'between:1,31'],
'dob_month' => ['digits_between:1,2', 'nullable', 'between:1,12'],
'dob_year' => ['digits:4', 'required']
//need to validate the date of birth if all 3 have values.
];
if (request()->has('dob_day')&&request()->has('dob_month')&&request()->has('dob_year')) {
$date = now();
$rules['full_date'] = 'before:'.now()->toDateString();
//Or if you don't want to use javascript you can do some extra checking here on the current date inputs and change their rules to fit or throw an exception
$rules['dob_year'][] = 'max:'.now()->year;
...
}
return $rules
}