field('MIN(`id`) AS `id`, MIN(`goods_id`) AS `goods_id`, `spec_id`') ->where('goods_id', $goods_id) ->with([ 'Spec', 'SkuValue' => function ($query) use ($goods_id) { $query->where('goods_id', $goods_id) ->field('id,goods_id,spec_id,spec_value_id') ->with(['SpecValue']); } ])->group('spec_id')->select(); $list = collection($list)->toArray(); return $list; } }