original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Nest items.
  
  @return mixed NestableCollection
docstring_tokens: Nest items .