-
Sometimes you want to redirect back, however without the query string. e.g. for the URL: However I would like to redirect to One could instead Is there already an elegant way to achieve this? (I did some research, but couldn't find anything useful.) If there isn't, could we maybe implement one of the following? return back(ignoreQuery: true); return redirect(url()->previous(ignoreQuery: true)); return redirect(url()->previousWithoutQuery()); If I'm not mistaken, the first and second possibilities might introduce breaking changes. The third possibility would be easy to implement in /**
* Get the URL for the previous request without the query string.
*
* @param mixed $fallback
* @return string
*/
public function previousWithoutQuery($fallback = false)
{
return rtrim(preg_replace('/\?.*/', '', $this->previous($fallback)), '/');
} Not sure if Then in turn, would make the following possible: /**
* Get the previous path info for the request.
*
* @param mixed $fallback
* @return string
*/
public function previousPath($fallback = false)
{
return str_replace($this->to('/'), '', $this->previousWithoutQuery($fallback));
} Enabling: return redirect(url()->previousPath()); I'd be happy to do a PR. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I think you can do this: // Redirect to same url with "ref" query string. Also accepts an array with keys.
return redirect()->away($request->fullUrlWithoutQuery('ref')); |
Beta Was this translation helpful? Give feedback.
-
@miclaus I think, the simple way is like this:
|
Beta Was this translation helpful? Give feedback.
-
@Kristories since PR #41661 you can do this: return redirect(url()->previousPath()); |
Beta Was this translation helpful? Give feedback.
@Kristories since PR #41661 you can do this: