I'm attempting to to remove random elements from a collection while iterating through a for loop. The idea is that each time it goes through the for loop, the items in the collection available doesn't include items found and removed in previous iterations. I've attempted to use forget on the initial collection, but i'm still finding doubles in the results. Any help would be appreciated, thanks!
- $data = SomeModel::get();
- for($i = 1; $i <= $max; $i++) {
- $random = $data->random($numberToPick);
- foreach($random as $option) {
- $data->forget($option->id);
- }
- }
I dd($data) at the end, and do indeed see the items selected are removed from the final collection, but as mentioned, i'm still getting some randoms that have keys matching previous iterations.