I have a multidimensional Laravel collection of pages for a navigation menu.
{
id: 1,
...
children: [
{
id: 2,
...
children: [
{
id: 3,
...
children: []
}
]
},
{
id: 4,
...
children: []
}
]
}
The collection has no limit on its depth or the amount of siblings for each tier. However, there is only one page at the root level. i.e. the first page (id 1) has no siblings. How can I extract all the ids into a single array?
expected output
[1,2,3,4]

pluck('children.id')? Not sure ifpluck()supports dot syntax.