public function generateTree($items)
    {
        foreach ($items->reverse()->all() as $index => $item) {
            $parent = $this->findParent($items, $item);

            if (isset($parent)) {
                $parent->setChild($item);

                $items->forget($index);
            }
        }

        return $items;
    }
public function generateTree($items)
    {
        foreach ($items->reverse()->all() as $index => $item) {
            $parent = $this->findParent($items, $item);

            if (isset($parent)) {
                $parent->setChild($item);

                $items->forget($index);
            }
        }

        return $items;
    }
public function generateTree ( $ items ) { foreach ( $ items -> reverse ( ) -> all ( ) as $ index => $ item ) { $ parent = $ this -> findParent ( $ items , $ item ) ; if ( isset ( $ parent ) ) { $ parent -> setChild ( $ item ) ; $ items -> forget ( $ index ) ; } } return $ items ; }
Transform flat menu structure into tree.

@param \Illuminate\Support\Collection $items

@return \Illuminate\Support\Collection
Transform flat menu structure into tree .