也就 幾行代碼 就 搞定了:
(1)後臺 數據庫 查詢數據庫時,需要使用:paginate(15) ; 意思是:查詢出來的數據 按照 每頁 15 條 在前臺進行展示。
如: $students = Student::where('success','1')->paginate(10);
(2)將查詢出來的數據 推送到 前臺 view頁面:
如:return view('admin.studentView',compact('student'));
(3)前臺 顯示 分頁 模塊:
循環打印student信息,並顯示出分頁模塊:
<ul>
@foreach($students as $student)
<li>{{$student->message}}</li>
@endforeach
</ul>
{{ $students->appends(['success' => '1'])->links() }}
上面這句就是 生成一個分頁 。
appends()是 爲 生成一個分頁 添加 的查詢條件,也就是後臺 Student::where('success',1) ,直接對應起來就行。
如果沒有任何的查詢條件:
後臺: Student::paginate(10);
前臺: {{$students->links()}}