Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel change get parameter in url string and return

I'm using get parameters for search filters, and need to be able to change a value of the query string variable and return the modified url (as a string variable, nothing fancy, no redirect or anything). This is what I have so far and what is happening:

public function index(Request $request){

    echo $request->fullUrl();
    // outputs https://test.com/search?type=somestring

    $request->merge(['type' => 'anotherstring']);

    echo $request->fullUrl();
    // still outputs https://test.com/search?type=somestring

    // is there a way to change a parameter value in the url and
    // return the modified url string?

}

I figure if worse comes to worse, I'll just parse the string manually, but it feels like there's a "laravel way" to go about this that I happen to be missing?

like image 891
whitwhoa Avatar asked Jun 05 '17 18:06

whitwhoa


1 Answers

Use fullUrlWithQuery instead.

echo $request->fullUrlWithQuery(['type' => 'anotherstring']);
like image 57
ayip Avatar answered Nov 13 '22 21:11

ayip