多个whereHas标准我有两个表 - 接触和访问:Laravel的关系
联系人表
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
使用侃侃而谈,我想检索所有联系人有一个路径名称 ='注册'和一个引用者 ='google'。
到目前为止,我已经得到了什么是:
Contact::whereHas('visits', function($query) {
$query->where('pathname','=','signup');
})
->orWhereHas('visits', function($query) {
$query->where('referrer','=','google');
})
->get();
哪个正确检索访问过的任何定价或注册页面的所有联系人。
但是,此示例还会检索Sally(来自上面的示例表),因为她访问了注册,但未被google引用。我需要一种方法来检索Joe,他们都是通过google引用并访问了定价。
任何想法?提前致谢!
这正是我所期待的。谢谢Marcin! – user3415951 2014-10-04 19:06:33