A
A
AleDv2016-06-04 14:38:57
Laravel
AleDv, 2016-06-04 14:38:57

How to merge collections in Laravel 5?

Hello. Apparently, the balls for the rollers have already stopped by, I just can’t think of how to merge the collections. In foreach I sort through users from which I take away certain objects, through hasMany. I get the following list of collections (from 2 users):

Collection {#683 ▼
  #items: array:1 [▼
    0 => PitSold {#693 ▶}
  ]
}
Collection {#699 ▼
  #items: array:3 [▼
    0 => PitSold {#700 ▶}
    1 => PitSold {#704 ▶}
    2 => PitSold {#705 ▶}
  ]
}

How can I then get one collection with all elements:
Collection {#699 ▼
  #items: array:4 [▼
    0 => PitSold {#693 ▶}
    1 => PitSold {#700 ▶}
    2 => PitSold {#704 ▶}
    3 => PitSold {#705 ▶}
  ]
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AleDv, 2016-06-04
@AleDv

Looks like I found the solution myself:
$collection->flatten();

V
Vyacheslav Plisko, 2016-06-04
@AmdY

Use map

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question