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>把总数
1 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
根据您的表,您正在执行错误的查询,因此,请执行以下操作:
$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');
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消