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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?