gpt4 book ai didi

mysql - Laravel 模型 - 想要检查 DB::raw 中的 where (or) orWhere

转载 作者:行者123 更新时间:2023-11-29 05:56:28 26 4
gpt4 key购买 nike

This is my model function now its working correctly, but i want to check where (or) orwhere. I Already try that but cant get the apt answer

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');

// i want to check this in my $countStatus something like and or condition in my db::raw query

最佳答案

使用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 Sometimes you may need to create more advanced where clauses such as "where exists" clauses or nested parameter groupings.

在您的情况下,您需要使用 where 闭包,因为您正在尝试 combine AND,OR 操作,这意味着您正在尝试对参数进行分组 在一个 block 中。这里的closure主要做了sql查询中parenthesis的作用。

关于mysql - Laravel 模型 - 想要检查 DB::raw 中的 where (or) orWhere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com