public function nest()
    {
        $parentColumn = $this->parentColumn;
        if (!$parentColumn) {
            return $this;
        }

        // Set id as keys.
        $this->items = $this->getDictionary();

        $keysToDelete = [];

        // Add empty collection to each items.
        $collection = $this->each(function ($item) {
            if (!$item->{$this->childrenName}) {
                $item->{$this->childrenName} = app()->make('Illuminate\Support\Collection');
            }
        });

        // Remove items with missing ancestor.
        if ($this->removeItemsWithMissingAncestor) {
            $collection = $this->reject(function ($item) use ($parentColumn) {
                if ($item->$parentColumn) {
                    $missingAncestor = $this->anAncestorIsMissing($item);

                    return $missingAncestor;
                }
            });
        }

        // Add items to children collection.
        foreach ($collection->items as $key => $item) {
            if ($item->$parentColumn && isset($collection[$item->$parentColumn])) {
                $collection[$item->$parentColumn]->{$this->childrenName}->push($item);
                $keysToDelete[] = $item->id;
            }
        }

        // Delete moved items.
        $this->items = array_values(Arr::except($collection->items, $keysToDelete));

        return $this;
    }
public function nest()
    {
        $parentColumn = $this->parentColumn;
        if (!$parentColumn) {
            return $this;
        }

        // Set id as keys.
        $this->items = $this->getDictionary();

        $keysToDelete = [];

        // Add empty collection to each items.
        $collection = $this->each(function ($item) {
            if (!$item->{$this->childrenName}) {
                $item->{$this->childrenName} = app()->make('Illuminate\Support\Collection');
            }
        });

        // Remove items with missing ancestor.
        if ($this->removeItemsWithMissingAncestor) {
            $collection = $this->reject(function ($item) use ($parentColumn) {
                if ($item->$parentColumn) {
                    $missingAncestor = $this->anAncestorIsMissing($item);

                    return $missingAncestor;
                }
            });
        }

        // Add items to children collection.
        foreach ($collection->items as $key => $item) {
            if ($item->$parentColumn && isset($collection[$item->$parentColumn])) {
                $collection[$item->$parentColumn]->{$this->childrenName}->push($item);
                $keysToDelete[] = $item->id;
            }
        }

        // Delete moved items.
        $this->items = array_values(Arr::except($collection->items, $keysToDelete));

        return $this;
    }
public function nest ( ) { $ parentColumn = $ this -> parentColumn ; if ( ! $ parentColumn ) { return $ this ; } // Set id as keys. $ this -> items = $ this -> getDictionary ( ) ; $ keysToDelete = [ ] ; // Add empty collection to each items. $ collection = $ this -> each ( function ( $ item ) { if ( ! $ item -> { $ this -> childrenName } ) { $ item -> { $ this -> childrenName } = app ( ) -> make ( 'Illuminate\Support\Collection' ) ; } } ) ; // Remove items with missing ancestor. if ( $ this -> removeItemsWithMissingAncestor ) { $ collection = $ this -> reject ( function ( $ item ) use ( $ parentColumn ) { if ( $ item -> $ parentColumn ) { $ missingAncestor = $ this -> anAncestorIsMissing ( $ item ) ; return $ missingAncestor ; } } ) ; } // Add items to children collection. foreach ( $ collection -> items as $ key => $ item ) { if ( $ item -> $ parentColumn && isset ( $ collection [ $ item -> $ parentColumn ] ) ) { $ collection [ $ item -> $ parentColumn ] -> { $ this -> childrenName } -> push ( $ item ) ; $ keysToDelete [ ] = $ item -> id ; } } // Delete moved items. $ this -> items = array_values ( Arr :: except ( $ collection -> items , $ keysToDelete ) ) ; return $ this ; }
Nest items.

@return mixed NestableCollection
Nest items .