Laravel - Get data last 24 hours, 1 week or 1 month

You wrote created_at > time.

So you ask laravel to search all data greater than now(). So you look into the future.

Either you want to...

  • look at points before a certain point in time: created_at < time

  • look at points after a certain point in time: created_at > time

  • look at points within an interval of passed time: created_at > start && created_at < end

If i got you right you are searching for the third option. So you need to do something like ...->where("created_at",">",Carbon::now()->subDay())->where("created_at","<",Carbon::now())->...

Hopefully, I got you right here.