我有一个查询,在这里我可以从相关表中获取所有数据,并获得总的分页.Now。我想在查询中设置分页参数。如果我的pagenumber=1和limit=2返回带有page=1和limit=2的1 and 2 rows数据,如果我发送page-3和limit-2,它返回5 and 6 rows和page-3.if page=null和limit=null返回所有数据。
我该怎么做呢。
我的函数:
Post::with(['product.categories.attributes'])->whereStatus("Active")->get();另外,如何在POSTMAN中传递此参数
发布于 2018-05-09 14:16:20
你所需要的就是跳过/抓取
https://laravel.com/docs/5.6/queries#ordering-grouping-limit-and-offset
你的代码应该是这样的:
public function show(Request $request) {
$perPage = $request->perpage;
if ($request->page == "") {
$skip = 0;
else {
$skip = $perPage * $request->page;
}
$result = Post::with(['product.categories.attributes'])
->skip($skip)
->take($perPage)
->where("Status", "Active")
->get();
}未设置$_POST‘’perpage‘的情况可在此处查看:
https://stackoverflow.com/questions/50246433
复制相似问题