Linus Odenring Linus Odenring - 1 month ago 21
PHP Question

Go back url Laravel 5.1

How can I get the previus url visited on the website in Laravel 5.1?

In Laravel 4 I just neede to write like

{{ URL::previous() }}

Answer

The cleanest way seems to be using the url() helper:

{{ url()->previous() }}

URL::previous() works for me in my Laravel 5.1 project. Here is Laravel 5.1 doc for previous() method, which is accessed through URL Facade.

You can still try alternatives, in your views you can do:

{{ redirect()->getUrlGenerator()->previous() }}

or:

{{ redirect()->back()->getTargetUrl() }}