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

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

    Did you test whereRaw()?

    so your function should look like:

    function scopeIsFeaturedOrIsBlogPost($query) {
        return $query->whereRaw('( isFeatured = "true" OR type = "blogPost" )');
    }
    

    ps. this is untested

提交回复
热议问题