我需要验证日期的格式。但日期字段不是必填字段。当我将该字段留空时,它会检查格式并引发错误。
'doc_date' => 'date_format:d-m-Y',
尝试修改您的验证器,使其看起来像这样:
'doc_date' => 'sometimes|date_format:d-m-Y'
如果始终发送输入,则可以尝试以下操作:
'doc_date' => 'filled|date_format:d-m-Y'
您可以在laravel中使用nullable
验证程序:
nullable
如果您不希望验证程序将空值视为无效,请尝试使用'doc_date' => 'nullable|date_format:d-m-Y',
:
nullable
'doc_date' => 'nullable|date_format:d-m-Y'
尝试这个:
Reference