Answer the question
In order to leave comments, you need to log in
How to merge laravel collections into one?
Hello. There are sites, each site has bugs, you need to get 1 total collection, so that later you can do pagination. I do this and always get an empty collection.
foreach ($sites as $site) {
//dd();
$collection->merge($site->bugs()->where('employee_id', $userId)->get());
}
$bugs1 = $sites[0]->bugs()->where('employee_id', $userId)->get();
$bugs2 = $sites[1]->bugs()->where('employee_id', $userId)->get();
$all = $collection->merge($bugs1)->merge($bugs2);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question