Is expires_at a datetime field?
You need to use where(condition1)->orWhere(condition2)
$alerts = Alert::whereNull('expires_at')
-orWhere('expires_at' > Carbon\Carbon::now())
->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've spent a good 2 or so hours debugging this already and I've attempted writing an actual MySQL query for this with no luck. What I have is a database table with alerts that have titles, descriptions, a type and an expiration date.
What I'm trying to do is get all of the alerts that either have no expiration date (they are non-expiring alerts) and all the alerts with expiration dates in the future. My current problem is that I can get alerts that have no expiration date but I either get no alerts with expiration in the future, or I get all the alerts that have expiration dates with the same year, even if the date is in the past.
The MySQL query that kind of works but really doesn't:
SELECT * FROM alerts WHERE (expires_at >= CURRENT_TIMESTAMP OR alerts.expires_at IS NULL)
Any help with this would be greatly appreciated!
Is expires_at a datetime field?
You need to use where(condition1)->orWhere(condition2)
$alerts = Alert::whereNull('expires_at')
-orWhere('expires_at' > Carbon\Carbon::now())
->get();
Please or to participate in this conversation.