laravel 商品无限级分类

//商品类别查询
public function topParent()
{
    $where['commodType_depth'] = 1;
    $where['commodType_status'] = 1;
    $where['commodType_parentId'] = null;
    return $this->where($where)->get(['commodType_id', 'commodType_name']);
}

//商品分类子集递归查询
public function child($commodType_id)
{
    $arr[] = Array();
    $where['commodType_status'] = 1;
    $where['commodType_parentId'] = $commodType_id;
    if ($arr = $this->where($where)->get(['commodType_id', 'commodType_name'])) {
        foreach ($arr as $k => $v) {
            $arr[$k]['child'] = $this->child($v->commodType_id);
        }
    }
    return $arr;
}

//商品分类列表  无限级
public function commod_type_list()
{
    $arr = $this->topParent();
    if ($arr) {
        foreach ($arr as $k => $v) {
            $arr[$k]['child'] = $this->child($v->commodType_id);
        }
    }
    return $arr;
}

你可能感兴趣的:(php,laravel)