user13523236
user13523236

Reputation: 135

Count today's records

I need to count only today's records

   public function sales()
{

    $h = Carbon::now(); 
    $recordstoday = Eventos::All();


    $data = [
        'category_name' => 'dashboard',
        'page_name' => 'sales',
        'has_scrollspy' => 0,
        'scrollspy_offset' => '',
    ];

    return view('dashboard',compact('recordstoday','h'))->with($data);
}

right now it counts all, but i need you to count today's records, to get today use Carbon

 <h4 class="card-text text-center"><b>{{$turnoshoy->count('created_at')}}</b></h4>

Upvotes: 0

Views: 48

Answers (2)

Sajedul Noman
Sajedul Noman

Reputation: 1

just use Carbon::today()

$recordstoday = Eventos::whereDate('created_at', Carbon::today())->get();

Upvotes: 0

John Lobo
John Lobo

Reputation: 15329

You can count using whereDate

ModelName::whereDate('created_at',now())->count();

for getting current month

$carbon=Carbon::now();

    ModelName::whereBetween('created_at',[
                                           $carbon->startOfMonth()->toDateString(),
                                           $carbon->endOfMonth()->toDateString()
                                      ])->count();

Upvotes: 2

Related Questions