Get only records created today in laravel

TheWebs picture TheWebs · Oct 21, 2015 · Viewed 109.8k times · Source

How do I use the created_at field to get only the records that were created today and no other day or time?

I was thinking of a ->where('created_at', '>=', Carbon::now()) But Im not sure that would work.

Answer

ashish picture ashish · Jun 18, 2018

for Laravel 5.6+ users, you can just do

    $posts = Post::whereDate('created_at', Carbon::today())->get();

Happy coding