Php Hot可获取属于其他用户关注的用户的帖子

Php Hot可获取属于其他用户关注的用户的帖子,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我有3个表用户,跟踪,帖子 用户表 id ... user_id designer_id user_id ... 下表 id ... user_id designer_id user_id ... 帖子表 id ... user_id designer_id user_id ... 如何从用户关注的设计师那里获得帖子?使用hasManyThrough,它提供通过中间关系访问远程关系的功能 定义关系如下: 用户模型 /** * Get all of the posts of

我有3个表
用户
跟踪
帖子
用户表

id
...
user_id
designer_id
user_id
...
下表

id
...
user_id
designer_id
user_id
...
帖子表

id
...
user_id
designer_id
user_id
...

如何从用户关注的设计师那里获得帖子?

使用
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');
}