laravel - get page number in object of laravel
问题描述
i have object given below and i wanted to pagination in this how can i get
$productListArray = array();
$productListObject = ((object)[
"id"=>$productList->id,
"title"=>$productList->title,
"slug"=>$productList->slug,
'categoryName'=>$categoryName[0]->cat_title,
'brand'=>$brandName[0]->brandname,
'minMrp'=>$minMrp,
'maxMrp' =>$maxMrp,
'minSellingPrice' => $minSellingPrice,
'maxSellingPrice' => $maxSellingPrice,
'rating'=>$productList->rating,
'rating_count' => $productList->rating_count,
'image' => $img[0]
])->paginate();
array_push($productListArray, $productListObject);
}
return response()->json($productListArray, 200);
解决方案
嗨,您可以使用 laravel 分页器获取当前页面Paginator::currentPageResolver
public function index()
{
$currentPage = 3; // You can set this to any page you want to paginate to
// Make sure that you call the static method currentPageResolver()
// before querying users
Paginator::currentPageResolver(function () use ($currentPage) {
return $currentPage;
});
$users = \App\User::paginate(5);
return view('user.index', compact('users'));
}
推荐阅读
- python - 如何在读取excel文件时停止python自动日期解析
- python - 调用 Discount 方法时,它不起作用
- rest - 我可以不带身份证 GET 吗?
- r - R:平方列联表
- java - 有没有办法将 Cloudlet 输出保存到 csv 文件?
- time - 验证字符串是否采用有效的时间格式
- typescript - nestjs 动态任务调度 - 上下文丢失
- amazon-web-services - 部署无服务器 Python 应用程序时的权限问题
- python - 在 django 模板中加载 iframe html 标签以显示地图
- javascript - 我的机器人得到这个错误,它的 js 但我不明白为什么我得到这个