Parenthesis in Eloquent Laravel query

I want to make a query with Laravel Eloquent in which I use parentheses to mount the conditions.

They are the products that are in stock and that the price is less than a quantity or that are on sale.

You could do something like this:

$products = Product::where(‘stock’, ‘>’, 0)->where(‘price’, ‘<', $quantity)->orWherePromotion(true)->get();

But that query is not what I want, because it would give me all the products that are on sale, together with those that are in stock or have a value less than a quantity.

To be clear, I want to use parentheses so my query looks like this:

where stock > 0 and (price < quantity or promotion = 1)

By using parentheses the query radically changes the results. But I don’t know how to do this in Eloquent.

See also  not found
Loading Facebook Comments ...
Loading Disqus Comments ...