如何使用laravel where子句?

Woo*_*ker 0 php laravel

我是Laravel的新人.如何将以下查询转换为Laravel where子句.

where category='1' and (shipping_from='1' OR shipping_to='2')
Run Code Online (Sandbox Code Playgroud)

Raf*_*gda 5

您应该使用嵌套参数分组:https://laravel.com/docs/5.6/queries#parameter-grouping.例如:

->where('category','1')
->where(function ($query) {
            $query->where('shipping_from', '1')
                  ->orWhere('shipping_to', '2');
        })
Run Code Online (Sandbox Code Playgroud)