如何设置分页并设置每页显示 5 项流明的限制
How to set pagination and set limit that show per page 5 items in lumen
如何设置分页和设置每页显示 5 项的限制。当我通过页码时它显示页面项目
class EmployeeController extends Controller{
public function index(){
$Employees = Employees::all();
$limit=5;
$itemPerPage=5;
$response = array();
$count = Employees::count();
$totalPage= ceil($count/$itemPerPage);
$response['totalPages'] = $totalPage;
$response['data'] = $Employees;
return response()->json($response);
}
尝试 laravel paginate
函数来获得分页结果
https://laravel.com/docs/5.4/pagination
尝试 laracasts 讨论频道中的示例代码
https://laracasts.com/discuss/channels/lumen/pagination-in-lumen?page=1
希望这会有所帮助
public function index(){
$Employees = Employees::all();
$page = Input::get('page', 1);
$itemPerPage=5;
$response = array();
$count = Employees::count();
$offSet = ($page * $itemPerPage) - $itemPerPage;
$itemsForCurrentPage = array_slice($Employees->toArray(), $offSet, $itemPerPage, true);
return new LengthAwarePaginator($itemsForCurrentPage, count($Employees), $itemPerPage, $page);
}
如何设置分页和设置每页显示 5 项的限制。当我通过页码时它显示页面项目
class EmployeeController extends Controller{
public function index(){
$Employees = Employees::all();
$limit=5;
$itemPerPage=5;
$response = array();
$count = Employees::count();
$totalPage= ceil($count/$itemPerPage);
$response['totalPages'] = $totalPage;
$response['data'] = $Employees;
return response()->json($response);
}
尝试 laravel paginate
函数来获得分页结果
https://laravel.com/docs/5.4/pagination
尝试 laracasts 讨论频道中的示例代码
https://laracasts.com/discuss/channels/lumen/pagination-in-lumen?page=1
希望这会有所帮助
public function index(){
$Employees = Employees::all();
$page = Input::get('page', 1);
$itemPerPage=5;
$response = array();
$count = Employees::count();
$offSet = ($page * $itemPerPage) - $itemPerPage;
$itemsForCurrentPage = array_slice($Employees->toArray(), $offSet, $itemPerPage, true);
return new LengthAwarePaginator($itemsForCurrentPage, count($Employees), $itemPerPage, $page);
}