I get all items from a table where:
endDate
is >= nowendDate
is NULL
published
equals 1
.This is what I have, but it gives me 0 items:
$items = Items::orderBy(\DB::raw('RAND()'))
->where('endDate', '>=', date("Y-m-d"))
->whereNull('endDate')
->where('published', '1')
->whereIn('cid', $this->activeId)
->orderBy('id')
->paginate(4);
Get data between two dates with MySQL Raw Query$startDate = '2022-06-01'; $endDate = '2022-06-30'; Post::whereBetween(DB::raw('DATE(created_at)'), [$startDate, $endDate])->get();
In pure SQL, we would use the IS NOT NULL condition, and the query would look like this: SELECT * FROM users WHERE last_name IS NOT NULL; The equivalent to the IS NOT NULL condition in Laravel Eloquent is the whereNotNull method, which allows you to verify if a specific column's value is not NULL .
You need to use a closure and the orWhereNull()
:
->where(function($q) {
$q->where('endDate', '>=', date("Y-m-d"))
->orWhereNull('endDate');
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With