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

yankeekid's avatar

Appending to existing HTTP Request

I have a complex search form setup on my Laravel site (for searching real estate listings). The form uses the GET method, so I have a long URL string once a search has been performed. The issue is that I want to implement a quick sorting method outside of the original form (using a secondary form with a simple select dropdown just above the results). The problem that I'm running into is that once the sort form has been submitted, I lose all of the previous request data. I've tried using the "old" method to get the previous request, and that works fine for one request, but since I can't put the query back into the URL, once the user hits the next page on the pagination links it's gone.

Instead of having the form replace the previous query string, I'd like to just append it to the existing query string in the URL. I know that the pagination class has a method for this, ( appends(request()->query()) ) but I can't seem to find anything within the docs about a similar method for HTTP Requests. I tried extracting the current URL string & tacking it to end of the "action" URL within the form, but this doesn't seem to work either.

Any ideas on how this can be done?

Any help would be appreciated. Thanks!

0 likes
2 replies
martinbean's avatar
Level 80

@lsheckell There’s absolutely no reason to modify the HTTP request to achieve this. If you manipulate a request in this way, then there’s no way to then trust it actually represents the request the user issued to your application.

Instead, keep using the query string. That’s what it’s for: for manipulating a resource. In your second form, you can pass the current query string parameters as key–value pairs so that they are re-submitted with your “quick sort” request:

{{ Form::open(['url' => 'property/search', 'method' => 'GET']) }}
    @foreach(request()->query() as $name => $value)
        {{ Form::hidden($name, $value) }}
    @endforeach
    {{ Form::label('sort') }}
    {{ Form::select('sort', $options) }}
    {{ Form::submit('Sort') }}
{{ Form::close() }}
1 like

Please or to participate in this conversation.