laravel 找不到四位数的年份 Carbon 中的数据丢失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43331377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:46:04  来源:igfitidea点击:

A four digit year could not be found Data missing in Carbon

phplaraveldate

提问by David McGregor

InvalidArgumentException: A four digit year could not be found
Data missing in carbon/src/Carbon/Carbon.php:425

Getting this error in my apache logs. What is the cause of this type of error?

在我的 apache 日志中收到此错误。此类错误的原因是什么?

回答by David McGregor

Running this on the date first should fix it. Likely getting an invalid date from the front-end.

首先在日期运行它应该可以解决它。可能从前端获取无效日期。

function validateDate($date, $format = 'Y-m-d H:i:s'){
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

function was copied from this answeror php.net

函数是从这个答案php.net复制的

回答by Yasir Ijaz

I faced and fixed that problem and problem was that I was using the guard method in the eloquent model and then I was trying to save data using create method. Problem was that the array I was providing to create method as a parameter has an extra column apart from the table's column so somehow our created_at or updated_at field was getting disturbed. Once I fixed the extra column issue. The error was removed.

我遇到并解决了这个问题,问题是我在 eloquent 模型中使用了 guard 方法,然后我试图使用 create 方法保存数据。问题是我提供给 create 方法作为参数的数组除了表的列之外还有一个额外的列,所以不知何故我们的 created_at 或 updated_at 字段被干扰了。一旦我修复了额外的列问题。错误已删除。