public static function children($menuLinks, $parentID = 0, $level = 1)
    {

        if($level == 1) {
            $fetchMenuList = $menuLinks->where('parent', null);
        }else{
            $fetchMenuList = $menuLinks->where('parent', $parentID);
        }

        //order List
        $fetchMenuList = $fetchMenuList->sortBy('order');

        if($fetchMenuList->count()) {
            $menuLinksList = new \stdClass();
            foreach ($fetchMenuList as $menuLink) {
                $menuLinksID = $menuLink->menuLinkID;
                $menuLinksList->$menuLinksID = $menuLink;
                $menuLinksList->$menuLinksID->children = self::children($menuLinks, $menuLink->menuLinkID, ($level + 1));

                //set active or no
                if (in_array($menuLink->menuLinkID, self::getActiveIDs())) {
                    $menuLinksList->$menuLinksID->isActive = true;
                } else {
                    $menuLinksList->$menuLinksID->isActive = false;
                }
            }
            return $menuLinksList;
        }
        return [];
    }
public static function children($menuLinks, $parentID = 0, $level = 1)
    {

        if($level == 1) {
            $fetchMenuList = $menuLinks->where('parent', null);
        }else{
            $fetchMenuList = $menuLinks->where('parent', $parentID);
        }

        //order List
        $fetchMenuList = $fetchMenuList->sortBy('order');

        if($fetchMenuList->count()) {
            $menuLinksList = new \stdClass();
            foreach ($fetchMenuList as $menuLink) {
                $menuLinksID = $menuLink->menuLinkID;
                $menuLinksList->$menuLinksID = $menuLink;
                $menuLinksList->$menuLinksID->children = self::children($menuLinks, $menuLink->menuLinkID, ($level + 1));

                //set active or no
                if (in_array($menuLink->menuLinkID, self::getActiveIDs())) {
                    $menuLinksList->$menuLinksID->isActive = true;
                } else {
                    $menuLinksList->$menuLinksID->isActive = false;
                }
            }
            return $menuLinksList;
        }
        return [];
    }
public static function children ( $ menuLinks , $ parentID = 0 , $ level = 1 ) { if ( $ level == 1 ) { $ fetchMenuList = $ menuLinks -> where ( 'parent' , null ) ; } else { $ fetchMenuList = $ menuLinks -> where ( 'parent' , $ parentID ) ; } //order List $ fetchMenuList = $ fetchMenuList -> sortBy ( 'order' ) ; if ( $ fetchMenuList -> count ( ) ) { $ menuLinksList = new \ stdClass ( ) ; foreach ( $ fetchMenuList as $ menuLink ) { $ menuLinksID = $ menuLink -> menuLinkID ; $ menuLinksList -> $ menuLinksID = $ menuLink ; $ menuLinksList -> $ menuLinksID -> children = self :: children ( $ menuLinks , $ menuLink -> menuLinkID , ( $ level + 1 ) ) ; //set active or no if ( in_array ( $ menuLink -> menuLinkID , self :: getActiveIDs ( ) ) ) { $ menuLinksList -> $ menuLinksID -> isActive = true ; } else { $ menuLinksList -> $ menuLinksID -> isActive = false ; } } return $ menuLinksList ; } return [ ] ; }
Get children of a menu link.

@param array $menuLinks the list of menuLinks of a Menu
@param INT   $parentID  the ID of menuLinkID that serves as a parentID to its children
@param INT   $level     What is the level of the menu. It automatically increases +1 for each child

@return object|array Returns all childrens of a given list of MenuLinks
Get children of a menu link .