function unique($key, $options = \SORT_REGULAR) {
        if($key === null) {
            return (new self(\array_unique($this->data, $options)));
        }
        
        $exists = array();
        return $this->filter(function ($item) use ($key, &$exists) {
            if(\is_array($item)) {
                if(!isset($item[$key])) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on array');
                }
                
                $id = $item[$key];
            } elseif(\is_object($item)) {
                if(!isset($item->$key)) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on object');
                }
                
                $id = $item->$key;
            } else {
                $id = $item;
            }
            
            if(\in_array($id, $exists, true)) {
                return false;
            }
            
            $exists[] = $id;
            return true;
        });
    }
function unique($key, $options = \SORT_REGULAR) {
        if($key === null) {
            return (new self(\array_unique($this->data, $options)));
        }
        
        $exists = array();
        return $this->filter(function ($item) use ($key, &$exists) {
            if(\is_array($item)) {
                if(!isset($item[$key])) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on array');
                }
                
                $id = $item[$key];
            } elseif(\is_object($item)) {
                if(!isset($item->$key)) {
                    throw new \BadMethodCallException('Specified key "'.$key.'" does not exist on object');
                }
                
                $id = $item->$key;
            } else {
                $id = $item;
            }
            
            if(\in_array($id, $exists, true)) {
                return false;
            }
            
            $exists[] = $id;
            return true;
        });
    }
function unique ( $ key , $ options = \ SORT_REGULAR ) { if ( $ key === null ) { return ( new self ( \ array_unique ( $ this -> data , $ options ) ) ) ; } $ exists = array ( ) ; return $ this -> filter ( function ( $ item ) use ( $ key , & $ exists ) { if ( \ is_array ( $ item ) ) { if ( ! isset ( $ item [ $ key ] ) ) { throw new \ BadMethodCallException ( 'Specified key "' . $ key . '" does not exist on array' ) ; } $ id = $ item [ $ key ] ; } elseif ( \ is_object ( $ item ) ) { if ( ! isset ( $ item -> $ key ) ) { throw new \ BadMethodCallException ( 'Specified key "' . $ key . '" does not exist on object' ) ; } $ id = $ item -> $ key ; } else { $ id = $ item ; } if ( \ in_array ( $ id , $ exists , true ) ) { return false ; } $ exists [ ] = $ id ; return true ; } ) ; }
Returns all of the unique items in the collection. Returns a new Collection.
@param mixed|null  $key
@param int         $options
@return \CharlotteDunois\Collect\Collection
@throws \BadMethodCallException
Returns all of the unique items in the collection . Returns a new Collection .