Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Paginating API HTTP Response in Laravel

 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));
}

 
PREVIOUS NEXT
Tagged: #Paginating #API #HTTP #Response #Laravel
ADD COMMENT
Topic
Name
8+2 =