我有 3 個表、users用戶表followpostsid
...跟隨表user_id
designer_id帖子表user_id
...如何獲取用戶關注的設計師的帖子?
1 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
使用hasManyThrough可以通過中間關系訪問遠程關系。
定義關系如下:
用戶模型
/**
* Get all of the posts of followed users.
*/
public function followedPosts()
{
return $this->hasManyThrough(
Post::class,
Follow::class,
'user_id',
'user_id',
'id',
'designer_id');
}
- 1 回答
- 0 關注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消