Answer
At User model add this methods:
public function posts()
{
return $this->hasMany(Post::class, 'user_id', 'id');
}
public function followers()
{
return $this->hasMany(Follower::class, 'user_id', 'id');
}
public function followers_posts()
{
return $this->hasManyThrough(Post::class, Follower::class);
}
public function shared_posts()
{
return $this->hasManyThrough(Post::class, SharedPost::class);
}
And eloquent query:
User::where('id', $foo_if)->with('posts', 'followers', 'followers_posts', 'shared_posts')->first();
0 comments:
Post a Comment
Thanks