0
這是我從2個不同的表中獲取數據的查詢。用(),select()和where()選擇的雄辯
$variant = Variant::with(['v_detail' => function($q){
$q->select('variant_dtl_name');
}])->where('product_id','=',$productId)->get();
有輸出,但v_detail
返回空列表
結果:
created_at: "2015-11-07 12:37:26"
id: 1
product_id: 30
updated_at: "2015-11-07 12:37:26"
v_detail: []
variant_name: "Pricing"
但是這些查詢:
$variant = Variant::with('v_detail')->where('product_id','=',$productId)->get();
結果是:
created_at: "2015-11-07 12:37:26"
id: 1
product_id: 30
updated_at: "2015-11-07 12:37:26"
v_detail: [{id: 1, variant_id: 1, variant_dtl_name: "Adult", variant_dtl_price: 25,…},…]
0: {id: 1, variant_id: 1, variant_dtl_name: "Adult", variant_dtl_price: 25,…}
1: {id: 2, variant_id: 1, variant_dtl_name: "Senior", variant_dtl_price: 15,…}
2: {id: 3, variant_id: 1, variant_dtl_name: "Children", variant_dtl_price: 8,…}
variant_name: "Pricing"
現在,在工作的查詢中,如何獲取特定的列名稱。謝謝!!