Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t0berius's avatar

get all entries created at specific date

How to get all entries created in a specific date range? For some project I would like to display a stats page, displaying for example deposits for each single day.

My code:

    $i = 1;
    while ($i <= 30) {
        
    $requested_day = Carbon::now()->subDays($i);

        $daily_deposits = Deposit::where('created_at')->get(); 


    }

How to get only the entries for the specific day?

All the best;

0 likes
1 reply
jbloomstrom's avatar

Consider querying all the deposits at once and then using a group function to group by day. It will ease the load on your database to do it all in one query. Like this:


// get all the deposits for the last month
$all_deposits = Deposit::where('created_at','>',Carbon::now()->subMonth())->get();

// now group by the created date
$all_deposits->groupBy( function($deposit) {
    return $deposit->created_at->format('Y-m-d');
});

Please or to participate in this conversation.