Level 51
$fiveDaysAgoDate = now()->addDays(-5);
$users = User::whereDate('expire_date', '=', $fiveDaysAgoDate->format('Y-m-d'))->get()
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a table with users and expires_date table, how do I write an Eloquent query to filter from the database and only pick users who have five(5) days more to the expiration date, by comparing the current date and expires date?
$users = User::whereDate('expire_date', now()->addDays(5))->get();
Please or to participate in this conversation.