Get only records created today in laravel(仅获取今天在 laravel 中创建的记录)
问题描述
如何使用 created_at
字段仅获取今天创建的记录,而没有其他日期或时间?
How do I use the created_at
field to get only the records that were created today and no other day or time?
我正在考虑 ->where('created_at', '>=', Carbon::now())
但我不确定这是否可行.
I was thinking of a ->where('created_at', '>=', Carbon::now())
But Im not sure that would work.
推荐答案
对于 Laravel 5.6+ 的用户,你可以这样做
For Laravel 5.6+ users, you can just do
$posts = Post::whereDate('created_at', Carbon::today())->get();
这篇关于仅获取今天在 laravel 中创建的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!