分享

子菜单数组方式

 shopnc 2016-12-27
public function index()
{
    $class_list = Category::orderBy('category_parent_id', 'asc')->orderBy('category_sort', 'asc')->orderBy('category_id', 'asc')->get()->toArray();
    $gc_list = array();

    foreach ($class_list as $key => $value) {
        $p_id = $value['category_parent_id'];//父级ID
        $cate_id = $value['category_id'];

        if ($p_id == 0) {//第1级分类
            $gc_list[$cate_id] = $value;
        } elseif (array_key_exists($p_id, $gc_list)) {//第2级
            $class2_ids[$cate_id] = $p_id;

            $gc_list[$p_id]['class2'][$cate_id] = $value;
        }
    }
         dd($gc_list);
    return view('category.index', ['list' => $gc_list]);
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多