Laravel 5 Eloquent where and or in Clauses

前端 未结 4 1015
轮回少年
轮回少年 2021-01-30 07:58

i try to get results from table with multiple where and/or clauses.

My SQL statement is:

SELECT * FROM tbl
WHERE m__Id = 46
AND
t_Id = 2
AND
(Cab = 2 OR          


        
4条回答
  •  情话喂你
    2021-01-30 08:35

    Using advanced wheres:

    CabRes::where('m__Id', 46)
          ->where('t_Id', 2)
          ->where(function($q) {
              $q->where('Cab', 2)
                ->orWhere('Cab', 4);
          })
          ->get();
    

    Or, even better, using whereIn():

    CabRes::where('m__Id', 46)
          ->where('t_Id', 2)
          ->whereIn('Cab', $cabIds)
          ->get();
    

提交回复
热议问题