0
votes

I have a named route I want to redirect to, while attaching the request query parameters leaving them in tact. I tried something like the following, which is throwing an exception: preg_match() expects parameter 2 to be string, array given

What's the correct way to do this?

return redirect($request->query())->route('foo.bar', ['name' => env('NAME')]);

This would redirect to the route named foo.bar with the parameter set in env('NAME') but also pass along all the query parameters in the original request.

1
fullUrlWithQuery might be what you neednice_dev

1 Answers

1
votes

Try:

$params = array_merge(['name' => env('NAME')], request()->query());
return redirect()->route('route.name', $params);

As per the docs:

The redirect function returns a redirect HTTP response, or returns the redirector instance if called with no arguments:

and:

The route function generates a URL for a given named route:

Reading Material