@hala, If you need to query Community created specific days before, you can use the ::whereDate function
Community::whereDate('created_at', Carbon::now()->subDays(3))
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this query
Community::where('created_at', Carbon::now()->subDays(3)->toDateString())
and in db i have this raw "created_at" : ISODate("2020-10-14T16:26:20.762Z")
but each time i made query data return empty
this
Community::where('created_at', Carbon::now()->subDays(3)->toDateString())
doesn't actually do anything because you need to actuall run the query you created.
The query is executed with get() if you expect a collection, or first() if you only want one answer
you dont need to use the toDateString since eloquent handles carbon objects directly
$records=Community::where('created_at', now()->subDays(3))->get();
bear in mind that this query uses times, so actually the time of day the record was created is also considered
Please or to participate in this conversation.