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

后端 未结 5 1975
不知归路
不知归路 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:22

    I'm a little late to the party, but wouldn't the most logical way be to wrap the where in a Closure?

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

提交回复
热议问题