You should be able to use the collection flatten and pluck method to achieve this:
- https://laravel.com/docs/5.8/collections#method-pluck
- https://laravel.com/docs/5.8/collections#method-flatten
$ids = $collection->flatten()->pluck('id');
Hello ,
I have this multidimensional collection bellow and I would like to get all id values to have at the end an array like [7,201,66,17,15,93,88,4,502]
Thanks
[
{
"id": 7,
"name": "Alvah Harris",
"team_leader_of_with_descendants": [
]
},
{
"id": 201,
"name": "Prof. Walker Cronin",
"team_leader_of_with_descendants": [
{
"id": 66,
"team_leader_of_with_descendants": [
]
},
{
"id": 17,
"name": "Dr. Hosea Lueilwitz IV",
"team_leader_of_with_descendants": [
{
"id": 15,
"avatar": "1566561953_5d5fd6a1ac6b2.png",
"team_leader_of_with_descendants": [
]
},
{
"id": 93,
"name": "Edyth Frami Sr.",
"team_leader_of_with_descendants": [
]
}
]
}
]
},
{
"id": 88,
"name": "Guadalupe Simonis Jr.",
"avatar": "user.jpg",
"team_leader_of_with_descendants": [
]
},
{
"id": 4,
"name": "Axel Windler",
"avatar": "user.jpg",
"team_leader_of_with_descendants": [
{
"id": 502,
"name": "Mostafa Abdellaoui",
"team_leader_of_with_descendants": [
]
}
]
}
]
Please or to participate in this conversation.