src/Traits/IsCollection.php
public function groupBy(string $key)
    {
        $items = [];
        foreach ($this->items as $item) {
            $items[$item[$key]][] = $item;
        }
        return new static($items);
    }
public function groupBy(string $key)
    {
        $items = [];
        foreach ($this->items as $item) {
            $items[$item[$key]][] = $item;
        }
        return new static($items);
    }
public function groupBy ( string $ key ) { $ items = [ ] ; foreach ( $ this -> items as $ item ) { $ items [ $ item [ $ key ] ] [ ] = $ item ; } return new static ( $ items ) ; }
Group by a given key

@param string $key Key to group by.
@return Collectable
Group by a given key