【问题标题】:Laravel WithCount using whereLaravel WithCount 使用 where
【发布时间】:2020-01-30 10:39:51
【问题描述】:

我有 3 张桌子:

  1. 表 1 courses

    • id_cours
    • field_cours
  2. 表 2 Question

    • id_quest
    • field_quest
    • id_cours
    • id_user
  3. 表 3 Users: -ID -nom

问题是我想统计用户刚刚添加的所有问题。

我在示范课程中尝试了这个: 但我想添加 id_user = id

 public function answers()
    {
        return $this->hasMany('App\QuestionUsers','idcours', 'id_cours');

    }

但这会返回所有用户添加的所有问题的计数。请需要帮助

【问题讨论】:

标签: php laravel-5 eloquent laravel-query-builder


【解决方案1】:

我找到了解决方案,只需调用 Auth 并添加位置


 public function answers()
    {
        return $this->hasMany('App\QuestionUsers','idcours', 'id_cours')->where('idusers',Auth::id());

    }

【讨论】:

  • 你在哪里使用 WithCount??
猜你喜欢
  • 2020-05-29
  • 2017-02-17
  • 2019-08-06
  • 2021-03-20
  • 2019-03-27
  • 2023-03-28
  • 2019-11-16
  • 2018-07-11
  • 2017-05-07
相关资源
最近更新 更多