使用Laravel和Carbon

使用Laravel和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?

我的数据库中有一个名为“deadline”的字段,它是DATE格式,我想用Eloquent来 如果截止日期字段与 Carbon :: now(); code>不匹配,但未来不存在,则不显示此行。 p>

如何 我能做到吗? p> div>

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.