Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if time is greater than created_at in database with carbon laravel

I want to write a code whereby if a user is created in my database the user must make payment. If the user does not make payment the user should be blocked. I have a column called blocked which is set to 0 by default, but if a user is blocked then its set to 1. On creation of account the created_at column is set to Carbon::now(), but if the user does not pay in 24 hours i want to block the user(i.e set the blocked column to = 1). Please help

like image 458
Paul Caleb Avatar asked Dec 18 '22 08:12

Paul Caleb


1 Answers

Use Carbon methods to check if user was created more than 24 hours ago. Add this clause to the query:

->where('created_at', '<', Carbon::now()->subDay())

Don't forget to add use clause to the top of the class where you run the query:

use Carbon\Carbon;
like image 181
Alexey Mezenin Avatar answered Apr 28 '23 08:04

Alexey Mezenin