private function convertToParentChild($menuLinks)
    {
        $tmp = [];
        $count = 0;
        foreach($menuLinks as $key => $menuLink){

            // Append menuLink Routes to each menu link
            if($menuLink['routeName']) {
                $route = Route::getRoutes()->getByName($menuLink['routeName']);
                if($route) {
                    $controller = Arr::last(explode('\\', get_class($route->getController())));
                    $routes = $this->getMenuLinkRoutes($controller, $menuLink['belongsTo']);

                    // Category
                    if($menuLink['belongsTo'] == 'category') {
                        $routeName = 'backend.postType.single';
                        $menuLink['href'] = route($routeName, ['view' => 'categoryupdate', 'id' => $menuLink['belongsToID']]);
                        $menuLink['routeList'] = $routes['list'];
                    }else if($menuLink['belongsTo'] == 'post_type') {
                        // Post Types
                        $routeName = 'backend.postType.single';
                        $menuLink['href'] = route($routeName, ['view' => 'update', 'id' => $menuLink['belongsToID']]);

                        $slugArr = array_first((array)$menuLink['slug']);
                        if($slugArr) {
                            $menuLink['routeList'] = $routes[$slugArr]['list'];
                        }
                    }else{
                        // Single post
                        $routeName = 'backend.post.single';
                        $menuLink['href'] = route($routeName, ['post_type' => $menuLink['belongsTo'],'view' => 'update', 'id' => $menuLink['belongsToID']]);
                        $menuLink['routeList'] = $routes['list'];
                    }

                }
            }

            $tmp[$count] = $menuLink;
            $children = $this->getChildren($menuLink['menuLinkID']);
            if(count($children)) {
                $tmp[$count]['children'] = $this->convertToParentChild($children);
            }
            $count++;
        }
        return $tmp;
    }
private function convertToParentChild($menuLinks)
    {
        $tmp = [];
        $count = 0;
        foreach($menuLinks as $key => $menuLink){

            // Append menuLink Routes to each menu link
            if($menuLink['routeName']) {
                $route = Route::getRoutes()->getByName($menuLink['routeName']);
                if($route) {
                    $controller = Arr::last(explode('\\', get_class($route->getController())));
                    $routes = $this->getMenuLinkRoutes($controller, $menuLink['belongsTo']);

                    // Category
                    if($menuLink['belongsTo'] == 'category') {
                        $routeName = 'backend.postType.single';
                        $menuLink['href'] = route($routeName, ['view' => 'categoryupdate', 'id' => $menuLink['belongsToID']]);
                        $menuLink['routeList'] = $routes['list'];
                    }else if($menuLink['belongsTo'] == 'post_type') {
                        // Post Types
                        $routeName = 'backend.postType.single';
                        $menuLink['href'] = route($routeName, ['view' => 'update', 'id' => $menuLink['belongsToID']]);

                        $slugArr = array_first((array)$menuLink['slug']);
                        if($slugArr) {
                            $menuLink['routeList'] = $routes[$slugArr]['list'];
                        }
                    }else{
                        // Single post
                        $routeName = 'backend.post.single';
                        $menuLink['href'] = route($routeName, ['post_type' => $menuLink['belongsTo'],'view' => 'update', 'id' => $menuLink['belongsToID']]);
                        $menuLink['routeList'] = $routes['list'];
                    }

                }
            }

            $tmp[$count] = $menuLink;
            $children = $this->getChildren($menuLink['menuLinkID']);
            if(count($children)) {
                $tmp[$count]['children'] = $this->convertToParentChild($children);
            }
            $count++;
        }
        return $tmp;
    }
private function convertToParentChild ( $ menuLinks ) { $ tmp = [ ] ; $ count = 0 ; foreach ( $ menuLinks as $ key => $ menuLink ) { // Append menuLink Routes to each menu link if ( $ menuLink [ 'routeName' ] ) { $ route = Route :: getRoutes ( ) -> getByName ( $ menuLink [ 'routeName' ] ) ; if ( $ route ) { $ controller = Arr :: last ( explode ( '\\' , get_class ( $ route -> getController ( ) ) ) ) ; $ routes = $ this -> getMenuLinkRoutes ( $ controller , $ menuLink [ 'belongsTo' ] ) ; // Category if ( $ menuLink [ 'belongsTo' ] == 'category' ) { $ routeName = 'backend.postType.single' ; $ menuLink [ 'href' ] = route ( $ routeName , [ 'view' => 'categoryupdate' , 'id' => $ menuLink [ 'belongsToID' ] ] ) ; $ menuLink [ 'routeList' ] = $ routes [ 'list' ] ; } else if ( $ menuLink [ 'belongsTo' ] == 'post_type' ) { // Post Types $ routeName = 'backend.postType.single' ; $ menuLink [ 'href' ] = route ( $ routeName , [ 'view' => 'update' , 'id' => $ menuLink [ 'belongsToID' ] ] ) ; $ slugArr = array_first ( ( array ) $ menuLink [ 'slug' ] ) ; if ( $ slugArr ) { $ menuLink [ 'routeList' ] = $ routes [ $ slugArr ] [ 'list' ] ; } } else { // Single post $ routeName = 'backend.post.single' ; $ menuLink [ 'href' ] = route ( $ routeName , [ 'post_type' => $ menuLink [ 'belongsTo' ] , 'view' => 'update' , 'id' => $ menuLink [ 'belongsToID' ] ] ) ; $ menuLink [ 'routeList' ] = $ routes [ 'list' ] ; } } } $ tmp [ $ count ] = $ menuLink ; $ children = $ this -> getChildren ( $ menuLink [ 'menuLinkID' ] ) ; if ( count ( $ children ) ) { $ tmp [ $ count ] [ 'children' ] = $ this -> convertToParentChild ( $ children ) ; } $ count ++ ; } return $ tmp ; }
Converts the one dimensional array of menu links to multidimensional array where each parent link has a object with
key 'children' where his children are stored.

@param  array|object $menuLinks
@return array
@throws \Exception
Converts the one dimensional array of menu links to multidimensional array where each parent link has a object with key children where his children are stored .