小编use*_*951的帖子

Laravel多个哪里有关系的标准

我有两张桌子 - 联系和访问:

联系表

id    | name          
----- | -------
1     | Joe
2     | Sally
Run Code Online (Sandbox Code Playgroud)

访问表

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
Run Code Online (Sandbox Code Playgroud)

使用eloquent,我想检索所有具有路径名 ='注册'和引用者 ='谷歌'的联系人.

到目前为止我得到的是:

Contact::whereHas('visits', function($query) {
    $query->where('pathname','=','signup');
})
->orWhereHas('visits', …
Run Code Online (Sandbox Code Playgroud)

relationship laravel eloquent

5
推荐指数
2
解决办法
9295
查看次数

标签 统计

eloquent ×1

laravel ×1

relationship ×1