我希望验证该audition_dates字段是否在shoot_dates之前。
我知道我可以通过这些规则来验证数组:
public function store(Request $request)
{
$validatedData = $request->validate([
'shoot_dates' => 'array',
'shoot_dates.*' => 'date',
'audition_dates' => 'array',
'audition_dates.*' => 'date'
]);
// The request is valid...
}我知道这些验证规则存在:
$rules = [
'start_date' => 'after:tomorrow',
'end_date' => 'after:start_date'
];但我不知道如何在数组上实现它们。
发布于 2020-04-24 10:46:08
至于您的代码,也如Laravel Documentation中所述
Validator::make($request->all(), $rules)->validate();我们把它放在函数的开头。您可以在我提供的文档链接中阅读有关如何创建规则的更多信息。
要在日期前进行验证,您必须执行以下操作:
'audition_dates' =>'required|date|before:date'日期必须按照strtotime,如果要对照其他字段,可能是:
'audition_dates' => 'required|date|before:shoot_dates'发布于 2020-04-24 13:21:16
我找到了一个解决方案。
[
'audition_dates' => 'required|array',
'audition_dates.*' => 'date|after:tomorrow',
'shoot_dates' => 'required|array',
'shoot_dates.*' => 'date|after:audition_dates.*',
];https://stackoverflow.com/questions/61400106
复制相似问题