I am looking to add objects to a new collection as I loop through a series of different results.
The query:
$osRed = Item::where('category', 'Hardware')
->where(function ($query) {
$query->where('operating_system', 'xxx')
->orWhere('operating_system', 'xxx')
->orWhere('operating_system', 'xxx');
})
->orderBy('operating_system', 'ASC')
->get();
Then, loop through these results and add related objects to a new collection.
foreach ($osRed as $os) {
foreach ($os->services as $service) {
if (!($servicesImpacted->contains($service))) {
$servicesImpacted->push($service);
}
}
}
I then go on to another set of results and add the related services from those results to the collection.
However, it is not picking up that the object is already in the collection and I end up with a large number of (what appear to be) duplicates.
Ideally, I would like to match up on the name attribute of the $service object, but that doesn't seem to be supported by the contains method.
toString() must not throw an exception