【问题标题】:blank page in next page in laravel paginationlaravel分页中下一页的空白页
【发布时间】:2020-02-18 09:40:30
【问题描述】:

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

【问题讨论】:

    标签: laravel


    【解决方案1】:

    在您看来,像这样使用集合/结果..

     @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
    

    【讨论】:

    • 通过输入dd($products)检查您是否将结果作为集合获得
    【解决方案2】:

    属性request-&gt;ram$request-&gt;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?

    【讨论】:

    • ya ram,存储必须传递到下一页。我这样做了 {{ $users->appends(['sort' => 'votes'])->links() }}以下文档,但问题仍未解决。
    • 我在过滤产品页面后遇到了这个问题。网址看起来像这样primestorenepal.ga/…。这是第一页
    • 在您的网站上,下一个链接的 URL 是“primestorenepal.ga/filter-listing-products?page=2”。变量不在查询字符串中。应该是“primestorenepal.ga/…
    • 如果您没有根据请求填写 brand_idbrand 查询变量,您的控制器似乎会中断。
    • 我以 {!! $products->appends(Request::except('page'))->render() !!} 并且它有效...感谢您的即时响应
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 2019-12-30
    相关资源
    最近更新 更多