0
我有兩個表,內容如下:想獲得以下以下JSON輸出
quote_glass_types
id | name
1 clear float glass
2 Tinted glass
quote_glass_type_thickness現在
id | quote_glass_type_id_fk | thickness
1 1 5mm
2 1 8mm
3 2 5mm
4 2 8mm
,我想加入這兩張桌子並得到Json如下:
[
{
id:1,
name: "clear float glass",
thickness:{"5mm","8mm" }
},
{
id:2
name:"tinted glass",
thickness:{"5mm","8mm"}
}
]
直到現在我都做過這樣的:
$glasssetting=\DB::table('quote_glass_types')
->join('quote_glass_type_thickness','quote_glass_type_thickness.quote_glass_type_id_fk','=','quote_glass_types.id')
->select('quote_glass_type_thickness.id','name','thickness')
->get();
return $glasssetting;
這給JSON,如:
[
{
"id": 1,
"name": "Clear Float Glasss",
"thickness": "5mm"
},
{
"id": 2,
"name": "Clear Float Glasss",
"thickness": "8mm"
},
{
"id": 3,
"name": "Tinted glass",
"thickness": "5mm"
},
{
"id": 4,
"name": "Tinted glass",
"thickness": "8mm"
}
]
如何獲得所需的JSON?
爲什麼你不使用雄辯? – Abhishek
我不確定你的意思是「我如何獲得所需的json」?你在你的視圖頁面上做了什麼? – Arminius
@Arminius我只想在我的數據庫表感謝你之後寫上面寫的特定類型的JSON響應。 – user3810794