I have a URL passed in a "next" variable in request query. The URL has its own query parameters. However, request()->query('next') strips away the query parameters starting with '&'
FULL URL: http://example.com/my-page?next=http://example.com/some-other-page?id=10&cat=123
But request()->query(‘next’) = http://example.com/some-other-page?id=10 which is wrong
as it has stripped away the remaining query parameters.
Laravel can't know whether &cat=123 belongs to /my-page or /some-other-page.
You have to encode the value:
$next = rawurlencode('http://example.com/some-other-page?id=10&cat=123');
$url = 'http://example.com/my-page?next='.$next;
See @staudenmeir's answer.
Most helpful comment
Laravel can't know whether
&cat=123belongs to/my-pageor/some-other-page.You have to encode the value: