在控制器中拥有dr_quantity
的总和,并返回视图模型
public function searchmedreport()
{
$search = \Request::get('search');
$total = DB::table('distribution_records')->where('id', Auth::user()->id)
->sum('medicine_name', 'LIKE', '%'.$search.'%');
$records = DistributionRecord::whereRaw("Concat(dr_fname,' ',dr_lname) LIKE '%{$search}%' ")
->orWhere('medicine_name','LIKE','%'.$search.'%')
->orWhere('date_requested','LIKE','%'.$search.'%')
->orderby('id')->paginate(5000);
return view('forms.searchmedreport',['records'=>$records,'total'=>$total]);
}
和
<b><h4>Total Number of Medicine Distributed: {{$total}} </b></h4>
输入总数
答案 0 :(得分:3)
根据您的表,您正在执行错误的查询,因此,请执行以下操作:
$total = DB::table('distribution_records')->where('id', Auth::user()->id)
->sum('medicine_name', 'LIKE', '%'.$search.'%');
您需要这个:
$total = DB::table('distribution_records')->where('user_id', Auth::user()->id)
->where('medicine_name', 'LIKE', '%'.$search.'%')->sum('dr_quantity');