由于我现在将大量数据放入数据库中,因此我需要使用 laravel 的分页。但是,它似乎不适用于我的其他查询。还有其他方法吗?或者我做错了什么?
我的代码如下所示
分页工作(ExamController)
$exams = Exam::with('users')->where('id',$userID)->paginate(5);
分页不起作用(问题控制器)
$questions = Question::with(['exams','choices'])->where('exam_id', $examID)->paginate(5);
显示分页的代码
{{ $exams->links() }} ---- exams view
{{ $questions->links()}} ---- questions view
错误
Call to undefined method App\Question::links()
看法
<div class="card">
<div class="card-body">
@foreach($questions as $index => $questions)
{{$questions}}
@endforeach
</div>
<div class="mt-3 d-flex justify-content-end text-right">
{{$questions->links()}}
</div>
</div>