Reputation: 741
I have a table (orders) where I have a 'status' column which allows null values. Here is an example of the table.
id | status |
---|---|
1 | 'Draft' |
2 | 'Draft' |
3 | null |
4 | 'Draft' |
when I write query like
Order::whereIn('status',['Draft'])->count()
it gives me expected number which is 3.
But when I revert the query like.
Order::whereNotIn('status',['Draft'])->count()
It don't give me the expected answer which is 1. Rather it gives me always 0. Can you please help me out?
Upvotes: 0
Views: 611
Reputation: 2495
Give it a try:
DB::connection()->enableQueryLog();
Order::whereNotIn('status',['Draft'])->orWhereNull('status')->count();
DB::getQueryLog();
Upvotes: 1