我怎么说WHERE (a=x AND b=y)
或(c=z AND d=j)
对于x,y,z ..是变量。
我如何用雄辩的方式做到这一点?
答案 0 :(得分:1)
您可以通过将闭包传递给查询构建器的where()
函数来实现此目的。这包含在文档http://laravel.com/docs/5.0/queries#advanced-wheres
$results = MyModel::where(function($query) {
$query->where('a', 'x')
->where('b', 'y');
})->orWhere(function($query) {
$query->where('c', 'z')
->where('d', 'j');
})->get();
答案 1 :(得分:1)
用于多个where语句:
$result = Model::whereRaw('(a = ? and b=?) or (c=? and d=?)', ['x','y','z','j'])->get();