gpt4 book ai didi

laravel - 相关模型的数据格式问题 (Laravel/jenssegers/laravel-mongodb)

转载 作者:行者123 更新时间:2023-12-03 15:59:36 39 4
gpt4 key购买 nike

这是一个open bug on Github对于 laravel-mongodb 包,但没有任何反应。也许有人知道解决方案..?

选择作为单个文档时,日期显示为日期

{
"_id": "5ca71ce0d542352064004034",
"title": "General review",
"status": "active",
"start_date": "2019-04-05 09:16:16.000000",
"end_date": "2038-01-19 03:14:07.000000",
"start_review_date": "2019-04-05 09:16:16.000000",
"submission_fee": 100,
"reward": 0,
"is_general_review_round": true,
"created_at": "2019-04-05 09:16:16.000000",
"updated_at": "2019-04-05 09:16:16.000000",
"proposals": [],
"demography": null
}

但是在选择作为相关对象(嵌套数组)时我遇到了这个日期转换问题...

{
"title": "Omnis perspiciatis aut voluptatem dolores vel repudiandae.",
"start_date": {
"$date": {
"$numberLong": "1554542206000"
}
},
"end_date": {
"$date": {
"$numberLong": "1556183806000"
}
},
"start_review_date": {
"$date": {
"$numberLong": "1555406206000"
}
},
"updated_at": {
"$date": {
"$numberLong": "1554455806312"
}
},
"created_at": {
"$date": {
"$numberLong": "1554455806312"
}
}
}

最佳答案

日期可以根据父模型进行格式化:如果您的父模型是 User 并且您正在嵌入 UserDetails 您可以通过以下方式转换日期:

public function userDetails()
{
return $this->embedsOne('UserDetails');
}

protected $dates = ['userDetails.created_at', 'userDetails.updated_at'];

关于laravel - 相关模型的数据格式问题 (Laravel/jenssegers/laravel-mongodb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55536466/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com