When you use the back()
method, it makes use of the UrlGenerator class, to be more specific, the previous()
method:
/**
* Get the URL for the previous request.
*
* @return string
*/
public function previous()
{
$referrer = $this->request->headers->get('referer');
$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
return $url ?: $this->to('/');
}
This method validates and removes url parameters before returning it, using the to()
method of the same class.
Taking this into account, if we use the first line of this method, we will get something like:
link
If you merge this with the redirect()
method, you will return to the same url as before, including its parameters. For example:
...
public function index()
{
// the previous url with the old params.
$url = request()->headers->get('referer');
return redirect($url);
}
...