【发布时间】:2020-09-19 05:15:49
【问题描述】:
我有一个帖子模型和控制器,当我尝试获取所有帖子时,它返回 created_at 和 updated_at 列,如下所示:
"created_at": "2020-05-31T22:04:38.000000Z",
如您所见,日期和时间之间有一个奇怪的“T”+末尾有“.000000Z”。
我尝试使用Carbon::setToStringFormat();,但没有成功。
这是我的 PostsController@index
{
Carbon::setToStringFormat(DateTime::ISO8601);
$posts = Post::with('author:id,name,lastName')->get();
return response()->json(['posts' => $posts->toArray()],200);
}
而且这个问题在我所做的每一个模型/迁移中都存在。包括 users 表。
"users": [
{
"id": 1,
"email": "admin@test.com",
"status": "admin",
"name": "Administrators",
"lastName": "Uzvārds",
"department": "client",
"phone": "null",
"created_at": "2020-05-31T22:03:36.000000Z",
"updated_at": "2020-05-31T22:03:36.000000Z"
},
{
"id": 2,
"email": "user@test.com",
"status": "employee",
"name": "Darbinieks",
"lastName": "Uzvārds",
"department": "client",
"phone": "null",
"created_at": "2020-05-31T22:03:36.000000Z",
"updated_at": "2020-05-31T22:03:36.000000Z"
}
]
【问题讨论】:
标签: laravel api axios laravel-api