我为患者考试制定时间表,他们看起来像这样:
当我点击一个病人将会显示他所做的所有检查时,使用的方法是:
return view('papeis.paciente.historico', [
'vinculos' => Vinculo::where('paciente_id',$id)->get()->sortByDesc('admissao')
->groupBy(function ($item, $key) {
return $item->admissao->format('d/m/Y');
}),
'paciente' => Paciente::findOrFail($id),
]);
患者考试(" Vinculo")是日期" admissao",以显示他当天所做的日期和考试。我不能将paginate用作集合,因此我不知道如何对groupBy集合进行分页。
答案 0 :(得分:1)
我不认为Laravel原生支持这一点,但你可以自己构建它:
$admissaoes = Vinculo::where('paciente_id', $id)->distinct()
->select('admissao')->orderByDesc('admissao')->get();
$page = Paginator::resolveCurrentPage() ?: 1;
$perPage = 5;
$pageAdmissaoes = $admissaoes->forPage($page, $perPage);
$paginator = new LengthAwarePaginator($pageAdmissaoes, $admissaoes->count(), $perPage, $page);
$vinculos = Vinculo::where('paciente_id', $id)
->whereIn('admissao', $pageAdmissaoes->pluck('admissao'))
->orderByDesc('admissao')->get();