Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel larvel查询((Key1=A和Key2=B)或(Key1=B和Key2=A))和Key3=C_Laravel_Eloquent - Fatal编程技术网

Laravel larvel查询((Key1=A和Key2=B)或(Key1=B和Key2=A))和Key3=C

Laravel larvel查询((Key1=A和Key2=B)或(Key1=B和Key2=A))和Key3=C,laravel,eloquent,Laravel,Eloquent,我按照以下方式为基本查询构建查询 // e.g. $params = ['id' => 'a', 'name' = 'ken'] foreach ($params as $key => $val) { $query->where($key, "=", $val); } 但是,我找不到一种方法来进行下面的复杂查询。如何构建查询 ((Key1=A and Key2=B) or (Key1=B and Key2=A)) and Key3=C 如果查询是(A或B)和(C或D)

我按照以下方式为基本查询构建查询

// e.g. $params = ['id' => 'a', 'name' = 'ken']
foreach ($params as $key => $val) {
  $query->where($key, "=", $val);
}
但是,我找不到一种方法来进行下面的复杂查询。如何构建查询

((Key1=A and Key2=B) or (Key1=B and Key2=A)) and Key3=C
如果查询是
(A或B)和(C或D)

如果需要
((x和y)或(z和v))和z

Model::where(function ($q) use ($a, $b) {
        $q->where(function($q) use($a, $b){
            $q->where('key1', $a)->where('key2', $b);
        })
        ->orWhere(function($q) use($a, $b){
            $q->where('key1', $b)->where('key2', $a);
        })
    })
    ->where('key3', $c)
    ->get();

很抱歉我没有及时回复。我不知怎的犯了语法错误。我正在努力修复它。
Model::where(function ($q) use ($a, $b) {
        $q->where(function($q) use($a, $b){
            $q->where('key1', $a)->where('key2', $b);
        })
        ->orWhere(function($q) use($a, $b){
            $q->where('key1', $b)->where('key2', $a);
        })
    })
    ->where('key3', $c)
    ->get();