date rule is evaluated before date_format
The field under validation must match one of the given formats. You should use either date or date_format when validating a field, not both.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have an API built with laravel. The code below always give error message "start_on/due_on doesn't match the date format d-m-Y H:i:s". Eventhough, my webapp/insomnia sends data with the correct format
Validation Code
$fields=$request->validate([
'project_id' => 'nullable',
'title' => 'required|string|max:255',
'description' => 'required|string',
'progress' => 'numeric',
'start_on' => 'nullable|date|date_format:d-m-Y H:i:s',
'due_on' => 'nullable|date|date_format:d-m-Y H:i:s',
'started_at' => 'nullable|date|date_format:d-m-Y H:i:s',
'complated' => 'boolean',
'completed_at' => 'nullable|date|date_format:d-m-Y H:i:s',
'completed_by' => 'nullable|numeric',
'tags' => 'array',
'tags.*' => 'numeric|distinct',
'assignees' => 'array',
'assignees.*' => 'numeric|distinct'
]);
Sent data
{
"project_id":"0",
"title":"Testing",
"description":"testing",
"tags":["2"],
"assignees":["0"],
"start_on": "18-5-2023",
"due_on": "25-5-2023 00:00:00"
}
Am i missing something? from the webapp/insomnia i put 00:00:00 to give set hour, minute, and second to fit the validation on due_on property. Yet, it still doesn't work
The d and m in the date format need to be with a leading zero. baed on your example (31-5-2023 23:59:59) looks like you are not considering leading zero for the month. If you want to use a date format without leading zeros for the day and month, you can use below format.
'start_on' => 'nullable|date_format:j-n-Y H:i:s',
Please or to participate in this conversation.