Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tigerjun's avatar

Query with special condition like 2%2 =0

When user buy two of the item will get a discount. Now the problem is when the user buy four qty of the product i cant match it out. Therefore i need to do some math in query. Like quantity%database.quantity == 0.

How can i do that in my query

        $promotionID = Promotion::where('product_id',$product)
			->whereRaw('promotion_quantity%'.$quantity.'=0')
                            ->get();
0 likes
1 reply
tigerjun's avatar
tigerjun
OP
Best Answer
Level 1

Promotion::where('product_id',$product) ->whereRaw('('.$quantity.'%promotion_quantity) = 0') ->get();

Please or to participate in this conversation.