Laravel多对多关系搜索

时间:2015-08-06 03:41:10

标签: laravel search eloquent many-to-many relationship

我现在有三个模特

用户

public function languages(){
    return $this->belongsToMany('App\Language');
}

public function languages(){
    return $this->belongsToMany('App\Language');
}

语言

public function users(){
    return $this->belongsToMany('App\User');
}

public function newspapers(){
    return $this->belongsToMany('App\Newspaper');
}

我已经拥有language_userlanguage_newspaper表格

在修补程序中,我已成功通过attach()blablabla检索这两种关系。

问题是 我怎样才能在{1}} {1}}中搜索Newspaper id1具有此User的啰嗦?对我来说这似乎很复杂。

Language

User id1 -> has language en, zh - >确定

Newspaper id1 -> has language en, jp - >不行

我试过这个,但不确定它是否正确

Newspaper id2 -> has language zh

$where = [];

1 个答案:

答案 0 :(得分:1)

您应该能够在此方案中使用-targetargs:"tests.dll /exclude:PerfomanceTests" ,如下所示:

whereHas