我要做的是获取模型的不同值(日期),并为每个日期显示相应的数据。当我对不同日期进行分页时,它工作正常,但在分页页面中,我看到所有结果而不是分开。这是我的功能:
public function showdaily($id) {
$capacities = array();
// DB::enableQueryLog();
$capacity_daily = CapacityDaily::select('for_date')->where('capacity_id', '=', $id)->orderBy('for_date', 'asc')->distinct()->paginate(2);
// dd(DB::getQueryLog());
foreach($capacity_daily as $cap) {
$get_capacity = CapacityDaily::where('capacity_id', '=', $id)->where('for_date', '=', $cap->for_date)->orderBy('for_date', 'asc')->distinct()->get();
$capacities[] = array('for_date' => $cap->for_date, 'values' => $get_capacity, 'capacity' => Capacity::find($id)->first());
}
return view('admin.capacity.daily', compact('capacities', 'capacity_daily', 'id'));
}
我在该表中共有4个不同的日期和96行。因为我想每页只显示2个日期,所以它应该只显示一个额外的页面,而不是我从1-47开始的。
我做错了什么?
答案 0 :(得分:0)
toSql()方法将显示它正在运行的查询,但我怀疑你需要对for_date进行分组而不是使用distinct
$capacity_daily = CapacityDaily::select('for_date')->where('capacity_id', '=', $id)->orderBy('for_date', 'asc')->groupBy('for_date')->paginate(2);