Waleed
Waleed

Reputation: 73

Get previous url in laravel

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

Upvotes: 1

Views: 5348

Answers (1)

Ozan Kurt
Ozan Kurt

Reputation: 3866

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();

Upvotes: 6

Related Questions