Laravel 5 date_format验证不会验证

时间:2016-10-01 13:36:50

标签: laravel laravel-5

这里是输入值:FIRST_TIME_ARRIVAL_DATE_AT_DAW : 2016-21-5 17:21:35这里是验证规则:

public static $createRules = [
      'FIRST_TIME_ARRIVAL_DATE_AT_DAW' => 'date_format:"Y-m-d H:i:s"',
];

并且它没有验证,它返回:

{"CELLS_EXPIRY_DATE":["The FIRST TIME ARRIVAL DATE AT DAW does not match the format Y-m-d H:i:s."]

编辑: 这是我的控制器的样子:

$validator = Validator::make($request->all(),BatteryAssets::$createRules);
        if ($validator->fails()) {
            return ['success' => 0, 'data' => 'Input error','errors' => $validator->messages()->toJson()];
        }

所以$validator->messages()->toJson()会返回验证错误

2 个答案:

答案 0 :(得分:2)

format Y-m-d H:i:s need be 2016-21-05 17:21:35

答案 1 :(得分:0)

'date_format:"Y-m-d H:i:s"'更改为'date_format:Y-m-d H:i:s'