I have this relation:
Each user has gallery and gallery hasMany files.
Two users can have a gallery of the same date.
This is the output JSON response:
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"
},
]
}
}
I need somehow to group galleries by created_at value, but to keep all files in same JSON response, for the groupped galleries object. Like this:
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"
},
]
}
},
I tried to use ->groupBy('galleries.created_at')
, but that I get this - first file from the first gallery, first file from the second gallery
Users {
galleries: {
created_at: 23.04.2019.
files: [
{
path: "path/to/file.jpg"
},
{
path: "path/to/file3.jpg"
},
]
}
},