【发布时间】:2017-12-21 09:23:38
【问题描述】:
对于一个新项目,我正在一家网上商店工作。我的产品与工厂细节有一对多的关系。工厂详细信息有一个列价格。我需要以第一个细节的价格订购产品。
如果我使用连接,我会按价格订购所有产品,但我会为每个详细关系获得一个新产品。
我试过了:
$products = $products->get();
$products = $products->sortBy(function ($product, $key) {
return $product->plantDetails()->first()->price; });
$products = $this->paginate($products, $perPage = 24, true);
}
$this->paginate 是:
public function paginate($items, $perPage = 15, $page = null, $options = []) {
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
但是我没有在分页链接中获得当前页面。有人有什么想法吗?
【问题讨论】:
-
你的意思是,当前页面从方法到渲染分页的链接像
$products->render()只显示什么,但其他页面显示像http://site.test/products?page=2这样的东西? -
$products->links() 按预期呈现分页,但 site.test/products 页面上的链接将是 site.dev/?page=2
-
您是否尝试删除
paginate上的第三个参数?还是手动设置分页器的路径?$this->paginate($products, 24)->setPath($request->url()); -
周二早上第一件事要试试
-
$this->paginate($products, 24)->setPath($request->url());工作。谢谢