仅获取今天在 laravel 中创建的记录

2021-12-23 00:00:00 date where mysql laravel-5.1 activerecord

如何使用 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();

相关文章