我有两个表格-联系人和访问:
联系人表
id | name
----- | -------
1 | Joe
2 | Sally
访问表
id | contact_id | pathname | referrer
----- | ------- | ------- | -------
1 | 1 | about | google
2 | 1 | pricing | null
3 | 1 | signup | null
4 | 2 | about | null
5 | 2 | signup | null
用雄辩的,我想找回所有的联系人有一个既有路径=“注册”和引荐=“谷歌”。
到目前为止,我得到的是:
Contact::whereHas('visits', function($query) {
$query->where('pathname','=','signup');
})
->orWhereHas('visits', function($query) {
$query->where('referrer','=','google');
})
->get();
可以正确检索访问过定价或注册页面的所有联系人。
但是,由于她访问了Signup,但该示例并未被google引用,因此该示例也会从上面的示例表中检索Sally。我需要一种方法来仅检索Joe,他既被Google推荐又访问了定价。
有任何想法吗?提前致谢!
您可以使用:
Contact::whereHas('visits', function($query) {
$query->where('pathname','=','signup');
})
->whereHas('visits', function($query) {
$query->where('referrer','=','google');
})
->get();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句