Lumen 如何设置分页和设置每页显示流明中5项的限制
如何设置分页和设置每页显示5项的限制。当我通过页码时,它会显示页面项目Lumen 如何设置分页和设置每页显示流明中5项的限制,lumen,Lumen,如何设置分页和设置每页显示5项的限制。当我通过页码时,它会显示页面项目 class EmployeeController extends Controller{ public function index(){ $Employees = Employees::all(); $limit=5; $itemPerPage=5; $response = array(); $count = Employ
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
函数获取分页结果
请尝试来自laracasts讨论频道的示例代码
希望这将有助于尝试laravel
分页
函数以获得分页结果
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);
}
请尝试来自laracasts讨论频道的示例代码
希望这将有助于检查我的答案更容易检查我的答案更容易
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);
}