Laravel 5 - Manual pagination

后端 未结 7 1601
情书的邮戳
情书的邮戳 2020-11-30 09:05

Pagination::make() method doesn\'t exist in Pagination class anymore in Laravel 5.

Is there a workaround to make manual pagination work in Laravel 5?

7条回答
  •  猫巷女王i
    2020-11-30 09:46

    Try below code for manual pagination

    40 && $item['id']<50){
                    array_push($filter_products, $item);
                }
            }
    
            $count = count($filter_products); // total product for pagination
            $page = $request->page; // current page for pagination
    
            // manually slice array of product to display on page
            $perPage = 5;
            $offset = ($page-1) * $perPage;
            $products = array_slice($filter_products, $offset, $perPage);
    
            // your pagination 
            $products = new Paginator($products, $count, $perPage, $page, ['path'  => $request->url(),'query' => $request->query(),]);
            // use {{ $products->appends($_GET)->links() }} to dispaly your pagination
            return view('index',['products' => $products]);
        }
    }
    

提交回复
热议问题