直接上代码
<?php
namespace ***;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
class FlowServer {
public function flow_info($request,$where,$time,$page_num){
$where = [];
$info = $table
->where($where)
->get();
$perPage = $page_num;
$total = count($info);
$page_info = [];
foreach($info as $v){
$page_info[] = $v;
}
if($request->has('page')) {
$current_page = $request->input('page');
$current_page = $current_page <= 0 ? 1 :$current_page;
} else {
$current_page = 1;
}
$total_page = ceil($total/$page_num);
$item = array_slice($page_info, ($current_page-1)*$perPage, $perPage);
$paginator =new LengthAwarePaginator($item, $total, $perPage, $current_page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page',
]);
$list = $paginator->toArray()['data'];
$re['list'] = $list;
$re['total_page'] = $total_page;
return $re;
}
}