dongyongyu0789 2014-07-23 19:05
浏览 12
已采纳

Laravel 4在GET请求上分页

I have a form that is used to filter results for a categories page. So, the URL will be localhost/public/search?keyword=blue however when I attempt to paginate() them the URL shows up as localhost/public/search?page=2 and so on. If I manually add the page=2 part to the end of the url it works fine but it's not adding it to the URL with the get request as needed. It needs to show up as localhost/search?keyword=blue&page=2

Not sure if needed but here is my method that handles the paginate()

        $category = Inventory::select('inventory_images.image', 'inventory.id' , 'inventory.sku', 'inventory.name', 'inventory.price', 'inventory_categories.category')
            ->join('inventory_categories', 'inventory.sku', '=', 'inventory_categories.sku')
            ->leftJoin('inventory_images', 'inventory.sku', '=', 'inventory_images.sku')
            ->where('inventory.active', '=', 1)
            ->where('inventory.stock_quantity', '>', 2)
            ->where('inventory.description', 'LIKE', '%'. Input::get('keyword') . '%')
            ->orWhere('inventory.name', 'LIKE', '%'. Input::get('keyword') . '%')
            ->groupby('inventory.id')
            ->take(1000)
            ->paginate(16);
  • 写回答

1条回答 默认 最新

  • dongqiang8474 2014-07-23 19:52
    关注

    The problem is in your view file, where pagination is printed.
    You need to append query parameters to links generated by Eloquent's paginator - which is pretty simple!

    <div class="pagination">
        {{ $model->appends(Input::except('page'))->links() }}
    </div>
    

    Note: you must append everything except the page query parameter. If you don't, it would be included twice in the URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答