我需要一个查询,该查询返回不喜欢帖子评论的用户

时间:2019-02-11 09:33:48

标签: php laravel

我可以得到是否喜欢此帖子的用户结果,但是如何获得不喜欢该评论的用户。

$posts = Post::select('id','title','slug','content','type','views','likes','shares','comments_count','followers','helpful_count','is_anonymously','user_id','created_at')
      ->with('user')
      ->with(['like' => function ($like) use ($user_id) {
      return $like->whereHas('user', function ($user) use ($user_id) {
            $user->where('id', $user_id);
            })->get();}])
      ->with('comments')
      ->where('is_spam',0)
      ->where('is_approved',1)
      ->where('group_id', $subgroup->id)
      ->orderBy('created_at','desc')
      ->paginate(3);
  return $posts;

帖子模型功能位于

下方
public function comments()
{
    return $this->hasMany('App\Models\Comment','post_id')
            ->where('parent_id',0)
            ->with('user','subComments','like')
            ->orderBy('id', 'desc');
}

评论模型

public function subComments()
{
    return $this->hasMany('App\Models\Comment', 'parent_id')->with('user','like);
}

0 个答案:

没有答案