我正在构建一个 API,我想将我的所有时间戳(如 created_at、deleted_at、... 等)作为复杂对象返回,包括实际的日期时间,还有时区。我已经在我的控制器中使用了 {Carbon/Carbon}。我也在模型中定义了我的日期字段。当我访问控制器中的日期字段时,我实际上得到了 Carbon 对象。但是当我将结果集作为 JSON 返回时,我只看到日期时间字符串。不是时区。
当前 JSON
{
"id": 4,
"username": "purusScarlett93",
"firstname": null,
"lastname": null,
"language_id": 1,
"pic": null,
"email": null,
"authtoken": "f54e17b2ffc7203afe345d947f0bf8ceab954ac4f08cc19990fc41d53fe4eef8",
"authdate": "2015-05-27 12:31:13",
"activation_code": null,
"active": 0,
"devices": [],
"sports": []
}
我的希望 :)
{
"id": 4,
"username": "purusScarlett93",
"firstname": null,
"language_id": 1,
"pic": null,
"email": null,
"authtoken":"f54e17b2ffc7203afe41d53fe4eef8",
"authdate": [
{
"datetime": "2015-05-27 12:31:13",
"timezone": "UTC+2"
}
],
"activation_code": null,
"active": 0
}
知道我在这里缺少什么吗?