📜  lengthawarepaginator 在第 2 页提供键 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:45.180000             🧑  作者: Mango

代码示例1
// On pages >= 2, the keys are returned since forPage returns an array with keys
// To fix this, just chain values() method.
$items_per_page = 10;
$current_page = LengthAwarePaginator::resolveCurrentPage();
$paginated_response = new LengthAwarePaginator(
      collect($items)->forPage($current_page, $items_per_page)->values(),
      count($items),
      $items_per_page,
      $current_page,
      ['path' => url('api/portfolios')]
);
return response()->json($paginated_response);