add get parameter to laravel's redirect method
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Adding GET Parameters to Laravel's Redirect Method
In this comprehensive blog post, we will address the issue of passing a GET parameter when performing a redirect in Laravel 5.6 and beyond.
The Problem with Default Redirect Behavior
When using the default redirect() method in Laravel, you may notice that any parameters provided in the original URL are not carried over to the new destination. This can cause issues if you need to maintain a particular query string or send additional data with your redirects.
Possible Solutions for Adding Parameters to Redirect Method
There are several approaches you can take when trying to pass on GET parameters in Laravel's redirect function:
Using Old-School Redirect Function: The
redirect()method is part of the Redirect Facade, which internally calls theto()method from the Response class. You can utilize the olderredirectTo()method instead, which preserves query parameters:phpreturn redirect()->to('/en/about', request()->query());However, this requires you to pass in the current request object and may not be suitable for all situations.
Using Custom Redirect Method: Create a custom function that allows you to pass query parameters while still using the standard
redirect()method. In your controller or helper class, create a newaddParamsToRedirect()method:phppublic function addParamsToRedirect($redirectUrl, $params = []) { return redirect()->to( $redirectUrl, request()->merge(request()->query(), true)->only($params) ); }This method takes the destination URL and optional parameters as arguments. It will merge the current query string with the desired ones and create a new request object. Then it uses the standard
redirect()method to redirect to the updated URL with all the relevant data maintained.Using Laravel Company's Redirector Package: A more robust solution can be found in Laravel Company's Redirector package. This add-on provides an improved redirect functionality, including support for preserving query strings and adding custom parameters:
phpuse Laravel\Redirector\Facades\Redirector; return Redirector::to('/en/about') ->withQuery($request->query()) // retain current query string ->merge(request()->input('param', null), 'param') // add new parameter ->execute();By using the
Redirectorclass and its features, you can easily manage and modify redirects with GET parameters.
Conclusion
Adding, preserving, or manipulating query strings when performing redirects in Laravel is possible through various approaches. You have a choice between the old-school method, creating custom functions, or using external packages such as the one provided by Laravel Company. Each method has its pros and cons based on your specific use case and development environment. Always remember to write clean, readable code and follow best practices for better maintainability and future scalability of your application.