嘿,我在我的表格中有不同的投诉状态,如活动的,关闭的等。我想要在我的仪表板中的活动投诉或关闭投诉的总数,但我不知道如何!
这是我的控制器,可以很好地处理用户和管理员的投诉总数:
public function index()
{
if(auth()->user()->role=='USER') {
$total = Complaint::where('user_id', auth()->user()->id)->count();
} else {
$total = Complaint::all()->count();
}
return view('dashboard', compact('total'));
}我只是使用{{ $total }}来显示投诉总数,但现在我想在仪表板中显示活动投诉的总数!我该怎么做呢?谢谢
发布于 2020-10-16 20:11:13
这应该是可行的:
$totals = DB::table('complains')
->select('status', DB::raw('count(*) as total'))
->where('user_id', auth()->user()->id)
->groupBy('status')
->get();https://stackoverflow.com/questions/64388785
复制相似问题