我如何改变查询字符串url值


Laravel how can I change query string url values?

我有一个搜索过滤器与值的最小和最大的价格(货币转换器),我想改变同一页上的货币的值,当我运行它在此刻的价格输入不会改变,直到我已经改变页面分页链接。

我像这样在view($max_price from controller)中添加价格:

 {!! Form::text('max_price',(int)$max_price,array('class'=>'sliderValue')) !!}

查询url字符串:

   www.example.com/items?search=min_price=0&max_price=1814
   $items->setPath('items');
   $items->appends(['search' => $input['search'], 'min_price' =>      
   $min_price, 'max_price' => $max_price]);

使用$request->replace($requestArray)

我无法使用replace()解决它,因为当我从$request->get('search')获得值时,它从queryString返回了原始值…

我做了什么:

use Symfony'Component'HttpFoundation'ParameterBag;
$oldQueryString = $this->request->query->all(); // To not lose other params
$params = [
    'search' => $input['search'], 
    'min_price' => $min_price, 
    'max_price' => $max_price
];
// Merge other params to the new ones
$newQueryString = array_merge($oldQueryString, $params);
$request->query = new ParameterBag($newQueryString);

现在当我使用$request->get('search')时,它返回给我新的值

Laravel 8+

也可以用

$request->instance()->query->set('min_price', $min_price);