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

shaiful's avatar

Request getQueryString() method not reflecting added params

public function index(Request $request) {

    $request->merge([
        'param1' => 'something',
        'param2' => 'something'
    ]);

    dd($request->getQueryString());

}

Hi all,

In the controller code above, I am not able to get the getQueryString() to output the correct query string based on the additional parameters added using the merge method. It seems to only capture the original parameters passed naturally from the URL in the browser.

How can I add parameters programmatically and generate the query string?

Thanks.

0 likes
2 replies
lostdreamer_nl's avatar
Level 53
    public function getQueryString()
    {
        $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));

        return '' === $qs ? null : $qs;
    }

getQueryString actually only gives you the real query string.

You can simply do this:


    $request->merge([
        'param1' => 'something',
        'param2' => 'something'
    ]);

    dd(http_build_query($request->all()));
1 like

Please or to participate in this conversation.