这是我的模型功能,现在它正常工作,但我想检查哪里(或)或其他地方。我已经尝试过,但无法得到合适的答案
public static function getPlacementCountByStatus(){
$countStatus = DB::table('placements')->where('status','1')->select(DB::raw('count(joborderid) as total, joborderid'))->groupBy('joborderid')->get();
return $countStatus;
}
我想检查一下这样的东西
->where('statusid','=','3')->orWhere('statusid','=','4')->orWhere('stageid','=','4')->orWhere('stageid','=','8');
//我想在我的$ countStatus中检查这个和我的db :: raw查询中的和/或条件
使用where()闭包:
$countStatus = DB::table('placements')->where(function($q){
$q->where('statusid','=','3')->orWhere('statusid','=','4')->orWhere('stageid','=','4')->orWhere('stageid','=','8');
})
->select(DB::raw('count(placementid) as total,statusid'))
->groupBy('statusid')->get();
return $countStatus;
From the docs
有时您可能需要创建更高级的where子句,例如"where exists"
子句或嵌套参数分组。
在你的情况下,你需要使用where closure
,因为你正在尝试combine AND,OR
操作,意味着你试图在块中的group your parameters
。这里closure
主要执行parenthesis
在sql查询中所做的事情。