计算今天的记录



我只需要计算今天的记录

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);
}

现在它计算所有,但我需要你计算今天的记录,以获得今天使用碳

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

您可以使用whereDate计数

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

用于获取当月

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

只需使用Carbon::today((

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

最新更新