0
我有三個表是如下:laravel加入三個表
invent_accessory ID,密碼,細節,is_length
invent_price_accessory ID,invent_accessory_id_fk,價格,顏色
invent_price_accessory_length id,invent_accessory_id_fk,price,color
我如何結合這三個表,這樣我可以得到ID,密碼,DETAL,is_length,價格,顏色
我做以下,但它不不返回任何數據:
public function getAccessoryInventPrice(){
$accessory=DB::table('invent_accessory')
->select('invent_accessory.id as accessory_id')
->join('invent_price_accessory','invent_price_accessory.invent_accessory_id_fk','=','invent_accessory.id')
->join('invent_price_accessory_length','invent_price_accessory_length.invent_accessory_id_fk','=','invent_accessory.id')
->get();
return $accessory;
}
我在猜測我必須做invent_price_accessory和invent_price_accessory_length然後加入invent_accessory?我該怎麼做呢?請幫助。
你缺少_fk –
謝謝你指出它。這只是一個打字錯誤。我編輯了我的帖子,但它不能解決我的問題。 – user3810794