LARAVEL 分页
自定义
public function index(Request $request)
{
$list = DB::table('auth_group')->where('status','!=','-1')->get()->toArray();
//dd($list);
$perPage = 3;
if ($request->has('page')) {
$current_page = $request->page;
$current_page = $current_page <= 0 ? 1 :$current_page;
} else {
$current_page = 1;
}
$item = array_slice($list, ($current_page-1)*$perPage, $perPage); //注释1
$total = count($list);
$paginator =new LengthAwarePaginator($item, $total, $perPage, $current_page, [
'path' => Paginator::resolveCurrentPath(), //注释2
'pageName' => 'page',
]);
$list = $paginator->toArray()['data'];
return view('AuthManager.index', compact('list', 'paginator')); //
//return view('AuthManager.index',['list'=>$list]);
}
<div class="pages">
{{ $paginator->render() }}
</div>
样式
<link rel="stylesheet" href="{{asset('css/app.css')}}">
简单模式
$list = DB::table('auth_group')->where('status','!=','-1')->paginate(1);
调用
{{$list->links()}}