Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

carlcassar's avatar

Link to append parameter to current query in URL

I once watched a video on the site about the following but can't seem to find it anywhere.

I have a form which is used to search by subject and postcode. The form makes a get request and the url then looks like:

http://example.com/search?subjects%5B%5D=Piano&postcode=SE10+5BE

Now I want to add a link to append another query, say within=10 to look like this:

http://example.com/search?subjects%5B%5D=Piano&postcode=SE10+5BE&within=10

I have two questions:

  1. How do I use a link to reload the page but add a parameter while not loosing the old ones.

  2. How do I use str_slug to make the url prettier (currently subjects[] is encoded as subjects%5B%5D

Thank you for your time! I'm happy to be pointed to a discussion or video!

0 likes
6 replies
pmall's avatar
  1. Add a hidden field ?

  2. It is search urls, you dont care if it is pretty or not.

carlcassar's avatar
  1. Thank you for your reply, but I can't add a hidden field as I want it to be a link like Jeffrey uses to filter lessons say.

  2. You're probably right, but the devil is in the detail?

Would be nice to have subject=piano&subject=guitar

pmall's avatar

You cant have what you want it would erase piano value with guitar.

Route::get('/search', ['as' => 'search', 'uses' => 'SomeController@search']);
route('search', ['subject' => ['piano', 'guitar'], 'other_value' => 'whatever']);
carlcassar's avatar
carlcassar
OP
Best Answer
Level 16

Thank you! That worked :)

{!! link_to_route('search', 'Within 10 miles', ['subject' =>Input::get('subjects'), 'postcode' => Input::get('postcode'), 'within' => '10'] ) !!}

Is it ok to use Input::get() in a view?

carlcassar's avatar

This is what I went with in the end:

 {!! link_to_route('search', 'Link', array_merge(Request::all(), ['anything'=>'else'])) !!}
1 like
yoosuf's avatar

Very simple method, when not using laravel collective html

<p>Already signed up? <a href="{{ route('login', array_merge(request()->all())) }}">Log in</a>  </p>

Please or to participate in this conversation.