Php 关系查询或where覆盖其他where
案例 基于几个问题的调查,根据调查结果返回Php 关系查询或where覆盖其他where,php,laravel,laravel-5,eloquent,laravel-5.3,Php,Laravel,Laravel 5,Eloquent,Laravel 5.3,案例 基于几个问题的调查,根据调查结果返回x公寓数量 公寓可以有一个固定价格(price),或一个价格范围(price\u min和price\u max)-并非所有公寓都有一个固定价格,因此它们是由价格范围定义的(例如900-1000月租金) 问题 没有或where([['price_min','!=',null],'price_max','!=',null],'price_min',''1')->where('floor','4'); } 如果($request->sun=='morning
x
公寓数量
公寓可以有一个固定价格(price
),或一个价格范围(price\u min
和price\u max
)-并非所有公寓都有一个固定价格,因此它们是由价格范围定义的(例如900-1000月租金)
问题
没有或where([['price_min','!=',null],'price_max','!=',null],'price_min',''1')->where('floor','4');
}
如果($request->sun=='morning\u sun'){
$query->where('sun','=','morning');
}elseif($request->sun=='nighlight\u sun'){
$query->where('sun','=','night');
}
如果($request->price==“1”){
$query->where('price','p>您需要对或where条件进行分组。以下操作可以实现此目的:
if ($request->price == '1') {
$query->where(function($q) {
$q->where('price', '<', '900')->orWhere([['price_min', '!=', null], ['price_max', '!=', null], ['price_min', '<', '900']]);
});
} elseif ($request->price == '2') {
$query->where(function($q) {
$q->where('price', '<', '999')->orWhere([['price_min', '!=', null], ['price_max', '!=', null], ['price_min', '<', '999']]);
});
}
if($request->price==“1”){
$query->where(函数($q){
$Q> >在哪里(‘价格’,‘个人’(因为我不知道LaaLVER),我会发现更容易孤立地考虑MySQL,然后留给你把这个查询转换成LaaLaveDyType是<代码> PrICEXMIN < /代码>?确保空字符串不同于NULL,所以也许应该在哪里<代码>‘Price’min’,‘!’,”“/Cuth>”。
if ($request->price == '1') {
$query->where(function($q) {
$q->where('price', '<', '900')->orWhere([['price_min', '!=', null], ['price_max', '!=', null], ['price_min', '<', '900']]);
});
} elseif ($request->price == '2') {
$query->where(function($q) {
$q->where('price', '<', '999')->orWhere([['price_min', '!=', null], ['price_max', '!=', null], ['price_min', '<', '999']]);
});
}