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

nasmo's avatar
Level 1

Laravel Query whereNull orWhere

Hello, i have to retreive a collection of products where the price is null or under a value. $products = Product::where('envoi_encheres',1) ->where(function ($query) use ($enchere) { $query->whereNull(self::PRIX_MIN) ->orWhere(self::PRIX_MIN, '<=', $enchere->prix); })

But when the product has a price at NULL, the line orWhere(self::PRIX_MIN, '<=', $enchere->prix); returns an "illegal operator and value combination" so even if the whereNull is true it does the orWhere test. How can I specify that if the first condition is true, to not check the rest ?

Thank you !!!

0 likes
1 reply
sr57's avatar

How can I specify that if the first condition is true, to not check the rest ?

Like you wrote.

Are you sure your error don't come form $enchere->prix that can be Null

Try, $enchere->prix ?? 0

Please or to participate in this conversation.