我试图获取与特定列表相关的所有ID,但我的查询只返回表中的第一个相关ID,而不是其他相关ID。Laravel:查询只获取一个相关的ID
表
List | id | person_id | name | description
| 1 | 10 | Test List | null
List_Ref | id | list_id | data_id
| 1 | 1 | 100
| 2 | 1 | 101
查询
$lists = DB::table('List')
->leftJoin('List_Ref', 'List_Ref.list.id', '=', 'List.id')
->select('List.id', 'List.name', 'List_Ref.data_id')
->where('person_id', Auth::user()->person_id)
->groupBy('List.id')
->orderBy('List.id')
->get();
结果(Laravel模具和转储)
#items: array:1 [
0 => {
"id" : 1
"name" : "Test List"
"data_id" " 100
}
]
我WOU ld喜欢产生如下结果
#items: array:1 [
0 => {
"id" : 1
"name" : "Test List"
"data_id" => {
"id" : 100
"id" : 101
}
}
]
您是否正在尝试替换get() - > all() –
如果您删除了group by,您将获得所需的所有结果。 –
@MubasharAbbas我需要将所有'data_id'分组到一个列表 –