【问题标题】:How to forbidden return comments with status unseen?如何禁止返回状态未见的评论?
【发布时间】:2018-07-10 21:25:14
【问题描述】:

我为获取 cmets 编写查询并为 post 回复commants。 评论和回复 cmets 放在 cmets 表上。 我的查询是:

$comments = Comment::with(['reply_comments', 'user', 'scores'])
            ->where('comments.place_id', $place[0]->id)
            ->where('status', 1)
            ->orderBy('id', 'desc')
            ->get();

虽然在 where 条件下检查 cmets 的状态,但此条件在 cmets 上完成,但不在 replyComment 上。 这意味着在看不到状态时返回回复评论。 如何为此更改查询或条件。

【问题讨论】:

    标签: php mysql laravel


    【解决方案1】:

    您也可以在with 中过滤关系:

    $comments = Comment::with(['reply_comments' => function ($query) {
              $query->where('status', 1);
            }, 'user', 'scores'])
            ->where('comments.place_id', $place[0]->id)
            ->where('status', 1)
            ->orderBy('id', 'desc')
            ->get();
    

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 2012-11-30
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      相关资源
      最近更新 更多