1

I have a search filter with with values for the min and max price(Currency converter) and I would like to change the value of the currency on the same page, when I run it at the moment the price input wont change until I've changed page with pagination link.

I append price like this on view($max_price from the controller):

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

the query url string :

   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]);

Solved it by using $request->replace($requestArray)

3
  • You may have to use AJAX for showing value on the current page itself. Commented Jun 28, 2016 at 2:53
  • I solved it by using eloquent "replace()" Commented Jun 28, 2016 at 15:36
  • Could you please provide the solution here, so that others may benefit from it? Commented Jun 29, 2016 at 2:28

2 Answers 2

1

I couldn't resolve it using replace(), because when I get the value from $request->get('search') it returned me the original value from the queryString...

What I did:

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);

Now when I use $request->get('search') it returns me the new value.

Sign up to request clarification or add additional context in comments.

Comments

1

Laravel 8+

We can also use

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.