我有这个关系:
每个用户都有画廊,画廊有很多文件。
两个用户可以拥有同一日期的画廊。
这是输出 JSON 响应:
User1 {
galleries: {
created_at: 23.04.2019.
files: [
{
path: "path/to/file.jpg"
},
{
path: "path/to/file2.jpg"
},
]
}
},
User2 {
galleries: {
created_at: 23.04.2019.
files: [
{
path: "path/to/file3.jpg"
},
{
path: "path/to/file4.jpg"
},
]
}
}
我需要以某种方式按 created_at 值对画廊进行分组,但是为了分组画廊对象,将所有文件保留在相同的 JSON 响应中。像这样:
Users {
galleries: {
created_at: 23.04.2019.
files: [
{
path: "path/to/file.jpg"
},
{
path: "path/to/file2.jpg"
},
{
path: "path/to/file3.jpg"
},
{
path: "path/to/file4.jpg"
},
]
}
},
我尝试使用->groupBy('galleries.created_at')
,但我得到了这个 - 第一个画廊的第一个文件,第二个画廊的第一个文件
Users {
galleries: {
created_at: 23.04.2019.
files: [
{
path: "path/to/file.jpg"
},
{
path: "path/to/file3.jpg"
},
]
}
},