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

andyandy's avatar

Eloquent ignore zero, but don't ignore NULL

I want ignore ZERO category. But it is also ignoring NULL.

Product::where('category', '<>', 0)->first();
Product::where('category', '!=', 0)->first();
Product::where('category', '!==', 0)->first();
Product::whereNotIn('category', [0])->first();
0 likes
2 replies
andyandy's avatar

@jlrdw Thanks, I didn't know that, so I did something like this.

Product::where(function($query){
	$query->where('category', '!=', 0)->orWhereNull('category');
})->first();

Please or to participate in this conversation.