How to combine WHERE clauses in Eloquent

前端 未结 5 923
轻奢々
轻奢々 2021-01-13 15:27

I would like to have this kind of query in Eloquent:

SELECT * FROM table WHERE status = 1 AND (type = 2 OR type = 3 OR type = 4)

I\'ve been

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 15:52

    you can try parameter grouping in where to achieve what you want.

    Table::where('status', 1)->where(function ($query) {
                $query->where('type', 2)
                      ->orWhere('type', 3)
                      ->orWhere('type',4);})
    

    For more info check laravel Query builder documentation.

提交回复
热议问题