Linus Odenring Linus Odenring - 10 months ago 136
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 Source

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


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