Devise\Menus\MenusRepository::getAllowedMenuItems PHP Method

getAllowedMenuItems() private method

This will let us know if the menu item is allowed and it also traverses all it's children (and future generations) filtering out menu items that are not allowed
private getAllowedMenuItems ( DvsMenuItem $menuItem ) : DvsMenuItem | false
$menuItem DvsMenuItem
return DvsMenuItem | false | false
    private function getAllowedMenuItems($menuItem)
    {
        $shown = $this->checkMenuItemPermission($menuItem->permission);
        // filter out children of this menu item for permissions too
        if ($shown && $this->childrenLoaded($menuItem)) {
            foreach ($menuItem->children as $key => $child) {
                $childShown = $this->getAllowedMenuItems($child);
                if (!$childShown) {
                    $menuItem->children->forget($key);
                }
            }
        }
        return $shown ? $menuItem : false;
    }