我在图表上工作,但是只输出一个用户的数据
$data = collect([]); // Could also be an array
for ($months_backwards = 2; $months_backwards >= 0; $months_backwards--) {
// Could also be an array_push if using an array rather than a collection.
$actMonth = Carbon::now();
$data->push(Slaughter::whereDate('dateOfDisplacement',$actMonth->subMonth($months_backwards))->count());
}
$chart1 = new AnimalChart;
$chart1->labels(['2 months ago','Last Month','Current Month']);
$chart1->dataset('Animal Slaughtered','line',$data)
->color($borderColors)
->backgroundcolor($fillColors);
return view('admin.index',compact(['users','chart','chart1','chart2']));
}
这是输出所有被宰杀的动物,但仅输出给第一个农场,而不是全部。换句话说,它仅输出动物farm_id为1(并非全部)的屠宰详细信息