需求:select * from table where a=1 and (b=2 or c=3)
结合实际业务需求($is)及laravel的when方法
$this->where('a',1)
->when($is,function($query){
$query->where('b',2)
->orWhere('c',3);
});
实际产生语句:select * from table where a=1 and b=2 or c=3
没在文档上找到这个问题的解决方案,求解
5 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
把它抱起来就好啦
$this->where('a',1)
->when($is,function($query){
return $query->where(function($query2){
$query2->orWhere('a' => b)->orWhere('c' => 'd');
//$query2->orWhere(['a' => b, 'c' => 'd']);
});
});
//select * from table where a = 1 and (a = b or c = d)
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
题主效率有问题.
select * from table where a=1 and b=2
union
select * from table where a=1 and b=3;
精慕HU
TA贡献1845条经验 获得超8个赞
$this->where('a',1)->where(function($query) use($is){
if($is)
$query->where('b',2)->orWhere('c',3);
});
- 5 回答
- 0 关注
- 540 浏览
添加回答
举报
0/150
提交
取消