public function indexBy($field)
    {
        $elements = $this->toArray();
        $this->clear();

        foreach ($elements as $element) {
            $this->set(
                $this->getFieldValue($element, $field),
                $element
            );
        }

        return $this;
    }
public function indexBy($field)
    {
        $elements = $this->toArray();
        $this->clear();

        foreach ($elements as $element) {
            $this->set(
                $this->getFieldValue($element, $field),
                $element
            );
        }

        return $this;
    }
public function indexBy ( $ field ) { $ elements = $ this -> toArray ( ) ; $ this -> clear ( ) ; foreach ( $ elements as $ element ) { $ this -> set ( $ this -> getFieldValue ( $ element , $ field ) , $ element ) ; } return $ this ; }
index collection by given object field.

@param string $field

@return EntityCollection
index collection by given object field .