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; } public function SkuValue() { return $this->hasMany('SkuSpec', 'spec_id', 'spec_id'); } public function Spec() { return $this->hasOne('Spec', 'id', 'spec_id', [], 'LEFT')->bind(['title' => 'name']); } public function SpecValue() { return $this->hasOne('SpecValue', 'id', 'spec_value_id', [], 'LEFT')->bind(['title' => 'value']); } }