我有一个表格,我要求开始时间和结束时间。我现在把它们作为字符串我想要检查请求结束时间不应该小于开始时间。 如何在laravel请求中实现这一目标?
public function rules()
{
return [
'hospital' => 'required',
'meeting_date' => 'required|after:yesterday',
'start_time' => 'required',
'end_time' => 'required'
];
}
答案 0 :(得分:0)
这是一个很好的解决方案,
$inputs = array(
'start_date' => '2013-01-20',
'end_date' => '2013-01-15'
);
$rules = array(
'start_date' => 'required|before_date:end_date',
'end_date' => 'required'
);
$messages = array(
'before_date' => ":attribute must be before :other"
);
$validation = Validator::make($inputs, $rules, $messages);
if( $validation->fails() )
{
echo '<pre>';
print_r($validation->errors);
echo '</pre>';
}//if it didn't validate
来自https://laravelish.wordpress.com/2013/02/21/compare-2-dates-from-input-in-validation/