1

I am trying to get previous url in laravel, I have tried this code,

        echo redirect()->back()->getTargetUrl();
        die();

when i simply echo this code, This correctly returns the url, but when i try to save it in some variable, It does not work

Waleed
  • 73
  • 1
  • 9
  • Does this answer your question? [Go back URL in Laravel 5.1](https://stackoverflow.com/questions/32826887/go-back-url-in-laravel-5-1) – Blake Sep 03 '21 at 13:52

1 Answers1

3

You can find it in the docs.

https://laravel.com/docs/8.x/urls#accessing-the-current-url

// Get the current URL without the query string...
echo url()->current();

// Get the current URL including the query string...
echo url()->full();

// Get the full URL for the previous request...
echo url()->previous();
Ozan Kurt
  • 3,731
  • 4
  • 18
  • 32