Laravel分页添加get参数

时间:2017-10-04 17:22:52

标签: php laravel-5

当我使用表单时,我有该URL

view-source:http://teory.loc/realty/appartment_rent/day?city=&district=&cost_up=29999&cost_to=333333&rooms_up=&rooms_to=&area_up=&area_to=&floor_up=&floor_to=

例如

为了处理这个URL,我使用了该代码

 public static function search($paginate, $condotions = null, $order = null){



    return AppartmentRentDay::where(function ($query) use ($condotions){
        foreach ($condotions as $key => $value){
            if($value){
                $parametrs = [];
                if(substr($key,-3) == "_up"){
                    $parametrs[0] = substr($key,0,-3);
                    $parametrs[1] = '>=';
                }elseif (substr($key,-3) == "_to"){
                    $parametrs[1] = '<=';
                    $parametrs[0] = substr($key,0,-3);
                }else{
                    $parametrs[0] = $key;
                    $parametrs[1] = '=';
                }
                $query->where($parametrs[0], $parametrs[1], $value);
            }
        }
    })->paginate($paginate);

}

Paginate工作正常,但{{ $info->links() }}是什么赋予了hrefs

<ul class="pagination">
           <li class="disabled"><span>&laquo;</span></li>
           <li class="active"><span>1</span></li>                                                                                
           <li><a href="http://teory.loc/realty/appartment_rent/day?page=2">2</a></li>
           <li><a href="http://teory.loc/realty/appartment_rent/day?page=2" rel="next">&raquo;</a></li>
        </ul>

这不正确,如何为此href添加我的获取参数?

Plz给我一些信息 泰 Laravel 5.5

1 个答案:

答案 0 :(得分:4)

您可以将现有参数附加到以下链接:

AppartmentRentDay::where(...)->paginate($paginate)->appends(request()->except('page'));