I would like to create a pagination in Rest API for Laravel. I want pagination like, Suppose I have total 30 categories in Database & I want to display 10 items in each page So total page will be 3 and 10 items will display in each page.
I have used paginate() method but it's only showing items by given number , I used below the script but it's not provided output that I mentioned.
$getCategories = Category::paginate();
$listCat = array();
foreach($getCategories as $val){
$cateName['id'] = $val->id;
$cateName['name'] = $val->name;
$cateName['description'] = $val->description;
$cateName['image'] = url('/').'/public/assets/images/category/'.$val->image;
$listCat[] = $cateName;
}
if(!empty($listCat)){
$respons['status'] = 'true';
$respons['message'] = 'Categories list';
$respons['data list']=$listCat;
}else{
$respons['status'] = 'false';
$respons['message'] = 'Category is not found.';
}
return Response::json($respons,200);
Does anybody tell me how could i use pagination in Rest Api?
I got output like..

