I have collections inside collection which look like that :
=> [
[
"id" => 3,
"parent_id" => 2,
"depth" => 1,
"children" => [
[
"id" => 4,
"parent_id" => 3,
"depth" => 2,
"children" => [
[
"id" => 5,
"parent_id" => 4,
"depth" => 3,
"children" => [
[
[...]
How can i work on that ? $result->count();
this return 1
It behave like there is only 1 collection so i can't even use map or each to filter it. I need to filter with a max depth of 4.
I tried reject() but it's not working neither.
I could transform it to array but i want to use the nice collection methods...
you need to iterate through your collection items
$result->children->map(function ($item) {
// do some stuff with $item or you can no map through its children
$item->children->map(function ($nestedItem) {
// do some stuff with $nestedItem etc//
});
});
an alternative would be to use foreach
statement though
First convert the collection to Array and then use
count($result, COUNT_RECURSIVE)