How do you wrap Laravel Eloquent ORM query scopes in parentheses when chaining?

后端 未结 5 1977
不知归路
不知归路 2021-02-12 14:47

In Eloquent, I\'d like to generate this query:

SELECT * FROM table WHERE a=1 AND ( b=2 OR c=3 );

But I seem to be generating this query instead

5条回答
  •  醉话见心
    2021-02-12 15:38

    You can generate parentheses by passing a callback function to where().

    Model::where('a',1)->where(function($query) {
        $query->where('b', 2)->orWhere('c',3);
    })->get();
    

提交回复
热议问题