Changing Laravel parameters on url bar and return

I am using get parameters for search filters and should be able to change the value of the query string variable and return the modified url (as a string variable, pretend nothing, redirect and nothing). This is what I have so far and what is going on:

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 suppose if it gets worse, I'll just parse the string by hand, but it looks like there is a "laravel way" to go about this, what am I missing?

+3


source to share


2 answers


Use fullUrlWithQuery

instead.



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

      

+6


source


Worse than what you can do:



 echo url()->current().(!empty($request->all())?"?":"").http_build_query($request->all());

      

0


source







All Articles