laravel分页中下一页的空白页

时间:2019-10-22 09:13:50

标签: laravel

laravel中的分页显示除第一页以外的其他页面中的空白页。

below is controller

$products=DB::table('products')->join('mobile_devices', 'products.id', '=', 'mobile_devices.product_id')->where('mobile_devices.brand', '=',$request->brand)
            ->where('mobile_devices.ram', '=', $request->ram)
            ->where('mobile_devices.storage', '=',$request->storage )
            ->select('products.*')->paginate(15);

below is blade
<div class="product-filter product-filter-bottom filters-panel">
                    <div class="row">
                        <div class="col-sm-6 text-left"></div>
                        <div class="col-sm-6 text-right">{{$products->links()}}</div>
                    </div>
                </div>

working fine in eloquent result but in query result the problem is occuring. The first page is shown but in other pages just blank page appears

2 个答案:

答案 0 :(得分:1)

属性request->ram$request->storage是否会延续到分页链接?如果您不添加它们,则可能不是它们。请参见https://laravel.com/docs/6.x/pagination#displaying-pagination-results

中文档中的“附加到分页链接”
$products = DB::table(...);
$products->appends([
    'ram' => $request->ram, 
    'storage' => $request->storage,
    'brand_id' => $request->brand_id,
    'brand' => $request->brand
]);

另请参阅How to automatically append query string to laravel pagination links?

答案 1 :(得分:0)

在您看来,使用收集/结果是这样的。

 @foreach($products as $product)
   {{$product->name}} // whatever you want to display
 @endforeach
 {{$products->links()}} // use the exact name of the object that you are passed to the view