当我尝试修改我的资源模型的默认 created_at 字段的格式时,我收到以下错误:
{
"error":{
"type":"InvalidArgumentException",
"message":"Unexpected data found.
Unexpected data found.
The separation symbol could not be found
Unexpected data found.
A two digit second could not be found",
"file":"\/var\/www\/html\...vendor\/nesbot\/carbon\/src\/Carbon\/Carbon.php",
"line":359
}
}
这是产生上述错误的代码:
$tile = Resource::with('comments, ratings')->where('resources.id', '=', 1)->first();
$created_at = $tile->created_at;
$tile->created_at = $created_at->copy()->tz(Auth::user()->timezone)->format('F j, Y @ g:i A');
如果我->format('F j, Y @ g:i A')
从上面的代码中删除,它可以正常工作,但它不是我想要的格式。问题可能是什么?我在我的应用程序的其他地方有几乎相同的代码,它可以正常工作。
更新:
使用setToStringFormat('F j, Y @ g:i A')
不会导致错误,但会返回null
.