Reputation: 135
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
Reputation: 1
just use Carbon::today()
$recordstoday = Eventos::whereDate('created_at', Carbon::today())->get();
Upvotes: 0
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