$users = User::paginate($request->get('perPage'));
$users->appends($request->all());
follow this link
https://github.com/spatie/laravel-json-api-paginate
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));
}