2
所以我試圖通過他們的帳戶訪問用戶註釋。基本上筆記不屬於用戶,它們屬於賬戶,用戶離開筆記仍然與賬戶相關聯。Laravel 5.2 HasThrough
這樣做是很難建立一個查詢。
這裏是它如何工作的:
Users->Distributors->Accounts->Notes
如果用戶有很多Distributors
(本地密鑰id
外鍵是user_id
)。 Distributors
有很多accounts
(本地密鑰vip_id
外鍵是dist_abbv
)。而Accounts
有很多Notes
(本地密鑰id
外鍵是account_id
)。
這是怎麼回事只是筆記?
似乎有道理。我應該提到這是在我的用戶模型中,因爲我只希望他們爲登錄用戶。所以我嘗試了'$ this-> with('distributors','distributors.accounts','accounts.notes') - > get()'並且調用未定義方法Illuminate \ Database \ Query \ Builder :: accounts( )' – Packy
@Packy用於登錄的用戶獲取註釋,您可以添加條件' - > where(['id'=> Auth :: user() - > id]) - > get();' –