📅  最后修改于: 2022-03-11 14:54:43.983000             🧑  作者: Mango
// 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);