As I mentioned, account must be suspended for 30 days
The last updated_at date must be more that 30 dates ago, so
$users = User::where('status', 'suspended')
->where('updated_at', '<=', today()->subDays(30)) // before 2022-03-18
->get()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to create a Task Scheduler in Laravel to reactivate suspended accounts after 30 days.
In Task Scheduler itself, I call and dispatch a Job. That Laravel Job handles reactivation and sending email to target users to let them know their account is reactivate.
All algorithm and system is easy for me to make but one things doesn't work and I have NO clue why it doesn't!!!
As I mentioned, account must be suspended for 30 days, so last updated_at must be last 30 days.
I have written this comparison statement in Laravel Eloquent but it doesn't work. Although if I remove line two of this code, it works.
Below code, is one possible solution I found on StackOverflow. Also, I changed updated_at column on database to last 35 to 40 days for some users.
Why date comparison using Carbon doesn't work in this case?
If anybody has a solution for this problem please comments below. Thank you.
use App\Models\User;
use Carbon\Carbon;
$users = User::where('status', 'suspended')
->where('updated_at', '>', now()->subDays(29)->endOfDay())
->get()
foreach ($users as $user) {
$user->status = null;
$user->save();
}
Please or to participate in this conversation.