Answer the question
In order to leave comments, you need to log in
How to add a new parameter to an existing query string?
How can I add new parameters to a query string that already has some parameters.
Those. Let's say that my current url is site?status=1 , and I need to click on the link, for example, to get the string site?status=1&color=2 . What do I need to write in the href attribute to get this result? I tried request()->fullUrlWithQuery(), but then it turns out that I have to specify a parameter and a value in the method, but if I have, for example, 10 parameters, it turns out that I need to specify each one.
Answer the question
In order to leave comments, you need to log in
I tried request()->fullUrlWithQuery(), but then it turns out that I have to specify a parameter and a value in the method, but if I have, for example, 10 parameters, it turns out that I need to specify each one.
If you would like to append query string data to the current URL, you may call the fullUrlWithQuery method. This method merges the given array of query string variables with the current query string:
<a href="{{ request()->fullUrlWithQuery(['status' => 1]) }}">Status</a>
<a href="{{ request()->fullUrlWithQuery(['color' => 1]) }}">Color</a>
this is how it works (welcome is the name of the route in the template of which this code is):
<div><a href="{{route('welcome', array_merge($_GET, ['a' => '1']))}}">a</a></div>
<div><a href="{{route('welcome', array_merge($_GET, ['b' => '1']))}}">b</a></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question