Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add withQuery, withoutQuery methods to redirect response #52562

Closed
wants to merge 5 commits into from
Closed

[11.x] Add withQuery, withoutQuery methods to redirect response #52562

wants to merge 5 commits into from

Conversation

iamgergo
Copy link
Contributor

@iamgergo iamgergo commented Aug 23, 2024

Sometimes it would be great to have the ability to manage query strings on the redirect response, like the fragment.

This PR allows to add, remove, replace query string parameters (even nested) on the target URL.

$url = '/login?loggedout=true';

$response = Redirect::to($url)
    ->withQuery(['status' => 'success'])
    ->withFragment('oauth-box')
    ->withoutQuery('loggedout');

$response->getTargetUrl(); // /login?status=success#oauth-box

If this PR accepted, I'll gladly update the docs as well.

@osbre
Copy link
Contributor

osbre commented Aug 23, 2024

I think there is already an alternative approach of passing parameters into the to_route helper second argument

@iamgergo
Copy link
Contributor Author

iamgergo commented Aug 24, 2024

Yes, but what if I want to redirect the user to a route without name, or to an external URL?

This solution is more generic than the to_route helper.

@taylorotwell
Copy link
Member

Going to hold off on this one for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants