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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器