Q:

Laravel Model - Want to check where (or) orWhere in DB::raw

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;
    }

I want to check something like this
->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

A:

Use where() closure:
$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.

In your case, you need to use where closure as you are trying to combine AND,OR operation, means you are trying to group your parameters in a block. Here closure mainly does what a parenthesis does in a sql query.

