«
laravel 集合数据首部追加新元素

时间:2022-2-24    作者:网络剑客    分类: php


/**
     * 分类列表
     * @return JsonResponse|object
     */
    public function getCategoryList()
    {
        $where[] = ['status', $this->param['status']];
        $categoryList = $this->shopCateRepo->getCategoryList($where);

        $all = [
            'id' => 0,
            'name_zh_cn' => '全部',
            'name_en_us' => '',
            'image' => '',
            'attr_specs' => [],
            'shop_count' => $this->shopRepo->findCount(['status' => 1]),
        ];
        $categoryList->prepend($all);//在集合首部追加元素

        return ApiResponse::Success($categoryList);
    }

标签: laravel