Paul Caleb
Paul Caleb

Reputation: 205

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

Upvotes: 4

Views: 10867

Answers (2)

Mahdi Sahib
Mahdi Sahib

Reputation: 130

whereColumn

The whereColumn method may be used to verify that two columns are equal

use Carbon\Carbon;

->whereColumn('created_at','<=', Carbon::today())

Upvotes: 2

Alexey Mezenin
Alexey Mezenin

Reputation: 163968

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;

Upvotes: 10

Related Questions