2016-12-13 70 views
0

你好,我有一個CommentRetours表格,它將評論連接到評論。如何在laravel關係中使用where查詢?

的DB:

enter image description here

我需要爲用戶顯示的所有意見,並返回到視圖。

我現在有這個疑問:

$comments = CommentRetours::with(['comments' => function($q) { 
     $q->where('user_id',Auth()->user()->id); 
    }])->get(); 

這返回NULL ..

的user_id是comments表內。

作爲建設淺析例如,我會補充一點:

enter image description here

我到底做錯了什麼?

+0

檢查'Auth() - > user() - > id'的輸出。我認爲它應該是'auth() - > user() - > id'。 –

+0

@iCode我檢查與dd();它返回正確的輸出 – Rubberduck1337106092

+0

你可以顯示你的「評論」關係嗎? –

回答

0

我通過將User_id添加到CommentRetours表中來修復它,現在我不必在其他關係中查詢。

我可以直接在表格中看到user_id。