简体   繁体   English

Laravel 4在GET请求上分页

[英]Laravel 4 paginate on GET request

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. 因此,URL将为localhost/public/search?keyword=blue但是当我尝试对其进行paginate()时,URL显示为localhost/public/search?page=2 ,依此类推。 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. 如果我手动将page=2部分添加到url的末尾,它可以正常工作,但并没有根据需要将其与带有get请求的URL相加。 It needs to show up as localhost/search?keyword=blue&page=2 它需要显示为localhost/search?keyword=blue&page=2

Not sure if needed but here is my method that handles the paginate() 不知道是否需要,但是这是我处理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);

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! 您需要将查询参数附加到Eloquent的分页器生成的链接上-这非常简单!

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

Note: you must append everything except the page query parameter. 注意:您必须附加除page查询参数之外的所有内容。 If you don't, it would be included twice in the URL. 如果不这样做,它将在URL中被两次包含。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM