[英]Laravel WithCount using where
i have 3 tables:我有 3 张桌子:
Table 1 courses
:表 1
courses
:
Table 2 Question
:表 2
Question
:
Users
: -id -nomUsers
:-id -nom The question is i want to Count all question just added by the user logged.问题是我想统计用户刚刚添加的所有问题。
i try with this one in the Model Courses: but i want to add where id_user = id我尝试在 Model 课程中使用这个:但我想添加 where id_user = id
public function answers()
{
return $this->hasMany('App\QuestionUsers','idcours', 'id_cours');
}
but this returns count of all question added by all users.但这会返回所有用户添加的所有问题的计数。 Please need Help
请需要帮助
i found solution just i call the Auth and add where我找到了解决方案,只是我调用了 Auth 并添加了 where
public function answers()
{
return $this->hasMany('App\QuestionUsers','idcours', 'id_cours')->where('idusers',Auth::id());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.