$items = new Collection([ ['id' => 1, 'name' => 'John Doe', 'score' => 10], ['id' => 2, 'name' => 'Jane Doe', 'score' => 8], ['id' => 3, 'name' => 'Adam Smith', 'score' => 10], ['id' => 4, 'name' => 'John Rock', 'score' => 8], ]); // key $groupedByScore = $items->groupBy('score'); $groupedByScore->each(function ($group, $score) { $group->each(function ($entity) use ($score) { $this->assertEquals($