Laravel模型 - 想要检查DB :: raw中的位置(或)或者哪里

时间:2018-02-28 06:52:03

标签: mysql laravel

  

这是我的模型功能,现在它正常工作,但我想检查哪里(或)或其他地方。我已经尝试过,但无法得到合适的答案

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查询中的条件

1 个答案:

答案 0 :(得分:2)

使用where()关闭:

<video width="400" controls>
    <source src={this.state.data} type="video/mp4" /> 
    Your browser does not support HTML5 video.
</video>
  

$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;   有时您可能需要创建更高级的where子句,例如   From the docs子句或嵌套参数分组。

在您的情况下,您需要在尝试"where exists"操作时使用where closure,这意味着您正在尝试combine AND,OR块中的group your parameters。这里closure主要执行parenthesis在SQL查询中的作用。