Lee_S_666
Lee_S_666

Reputation: 25

Using Laravel and Carbon

I have a field in my database called "deadline" which is of DATE format, and I want to use Eloquent to say that if the deadline field does not match Carbon::now(); but isn't in the future then don't show this row.

How can I achieve this?

Upvotes: 0

Views: 546

Answers (1)

Brian Dillingham
Brian Dillingham

Reputation: 9356

Select records where deadline is greater than or equal to today's date() in the Y-m-d format.

Model::where('deadline','>=', date('Y-m-d'))->get();

Laravel works with Carbon for formatting timestamps etc, which you can easily set the deadline column as one of those Carbon objects with a Laravel date mutator allowing you formatting abilities.

But for a select statement, i'd just use the above personally.

Upvotes: 2

Related Questions