检查一个日期比另一个更大,然后想要在laravel 4中抛出错误消息
if($_POST['TP_cab_travel_date_return'] < $_POST['TP_cab_travel_date'])
{
$rules['TP_cab_travel_date_return'] = 'required';
$messages = array( 'TP_cab_pickup_address.required' => 'Return date should
be less than start date.');
}
答案 0 :(得分:1)
Laravel验证检查统计和结束日期如下,$request
变量获取laravel中的帖子值
我在这里提到的日期格式为Y-m-d
您需要包含use Illuminate\Http\Request;
才能使用Request
对象
public function myfunc(Request $request)
$this->validate($request,[
'TP_cab_travel_date'=>'required|date_format:Y-m-d',
'TP_cab_travel_date_return'=>'required|date_format:Y-m-d|after:TP_cab_travel_date',
]);
}
答案 1 :(得分:0)
在这种情况下,你可以使用 strtotime() php功能检查function.strtotime.php
像这样
if(strtotime($_POST['TP_cab_travel_date_return']) < strtotime($_POST['TP_cab_travel_date']))
{
$rules['TP_cab_travel_date_return'] = 'required';
$messages = array( 'TP_cab_pickup_address.required' => 'Return date should
be less than start date.');
}
答案 2 :(得分:0)
您可以使用验证器本身:
$rules['TP_cab_travel_date_return'] = 'required|date_format:m-d-Y|after:TP_cab_travel_date';
$messages = array( 'TP_cab_pickup_address.after' => 'Return date should
be less than start date.');
注意:date_format是正常工作所必需的