#Best Pagination for Api's in laravel using eloquent
$billerCategories = BillerCategory::select('id', 'name', 'sp_key', 'category_order', 'sp_name', 'api_id', 'address_flag')->paginate(10);
return Ipay::response([
'statusCode' => 'TXN',
'status' => 'Biller categories fetched successfully',
'data' => [
'meta' => [
'totalPages' => $billerCategories->lastPage(),
'currentPage' => $billerCategories->currentPage(),
'totalRecords' => $billerCategories->total(),
'recordsOnCurrentPage' => $billerCategories->count(),
'recordFrom' => $billerCategories->firstItem(),
'recordTo' => $billerCategories->lastItem(),
],
'records' => $billerCategories->items(),
],
]);
public function paginate ($items, $perPage =4, $page = null) {
$page = $page ?: (LengthAwarePaginator::resolveCurrentPage() ?:1);
$total = count($items);
$currentpage =$page;
$offset = ($currentpage * $perPage) - $perPage;
$itemstoshow =array_slice($items, $offset, $perPage);
return new LengthAwarePaginator($itemstoshow, $total, $perPage);
}
public function fetch() {
//connect to api
$collection= Http::get('192.168.1.19/EnwealthWebAPi/ke/enwealth/contributions?memberNo=KEMI-002&company=KEMI%20SRBS')->json();
// return view('test', ['collection' =>$collection['value']]);
return view('test', ['collection' =>$collection['value']]-paginate(20));
}