I am trying to use a datetime format rule for my input like this:
H:i:s
My model rule looks like this:
public static $rules = [
...
'start' => [
'min:8',
'date_format:"H:i:s"',
],
];
And in my controller I call it like this:
$validator = Validator::make($request->all(), Product::$rules);
if($validator->fails())
{
return Redirect::back()->withInput()->withErrors($validator);
}
If I dd($validator)
I get following:
#rules: array:7 [▼
...
"start" => array:2 [▼
0 => "min:8"
1 => "date_format:"H:i:s""
]
]
I insert 00:h:01 into the input field but I did not get any error message.
Remove 'min:8' and then test again
public static $rules = [
...
'start' => [
'date_format:"H:i:s"',
],
];
FYI, Laravel date_format rule internally use date_parse_from_format() for validation
For more info: https://laravel.com/docs/5.1/validation
I have just checked and it worked for me:
print_r(date_parse_from_format("H:i:s", "00:h:01"));