src/Collection/Mutable.php
public function stack($elements, $groupId, $position = null): self
    {
        $group = new Group($groupId);

        $this->filter(function ($element) use ($elements) {
            return in_array($element->id(), $elements, true);
        })->each(function ($element) use ($group) {
            $group->push($element);
            $this->items = $this->without($element->id())->all();
        });

        if ($position) {
            $this->insert($group, $position);
        } else {
            $this->push($group);
        }

        return $this;
    }
public function stack($elements, $groupId, $position = null): self
    {
        $group = new Group($groupId);

        $this->filter(function ($element) use ($elements) {
            return in_array($element->id(), $elements, true);
        })->each(function ($element) use ($group) {
            $group->push($element);
            $this->items = $this->without($element->id())->all();
        });

        if ($position) {
            $this->insert($group, $position);
        } else {
            $this->push($group);
        }

        return $this;
    }
public function stack ( $ elements , $ groupId , $ position = null ) : self { $ group = new Group ( $ groupId ) ; $ this -> filter ( function ( $ element ) use ( $ elements ) { return in_array ( $ element -> id ( ) , $ elements , true ) ; } ) -> each ( function ( $ element ) use ( $ group ) { $ group -> push ( $ element ) ; $ this -> items = $ this -> without ( $ element -> id ( ) ) -> all ( ) ; } ) ; if ( $ position ) { $ this -> insert ( $ group , $ position ) ; } else { $ this -> push ( $ group ) ; } return $ this ; }
Join existing elements to a group.

@param $elements
@param $groupId
@param null $position

@return $this
Join existing elements to a group .