Laravel back button

I am trying to create a simple back button on a page. A user can go to this page from two different pages, so I would like to know which page he came from. Is it possible?

+67
php laravel
Sep 08 '12 at 19:21
source share
9 answers

In Laravel, you can do something similar to this: <a href="{{Request::referrer()}}">Back</a> (assuming you are using a blade server).

In Laravel 4

 {{ URL::previous() }} 

Laravel Documentation

+122
Sep 08 '12 at 19:33
source share

I know this is an old question, but I found it looking for the same solution. The above solution does not seem to work in Laravel 4, however you can use it now:

 <a href="{{ URL::previous() }}">Go Back</a> 

Hope this helps people looking for this feature in L4

(Source: https://github.com/laravel/framework/pull/501/commits )

+68
Jun 10 '13 at 19:21
source share

Laravel 5.2+, back button

 <a href="{{ url()->previous() }}" class="btn btn-default">Back</a> 
+47
Mar 20 '16 at 13:55
source share

The following is the full Blade (using the Laravel modeling algorithm):

 {!! link_to(URL::previous(), 'Cancel', ['class' => 'btn btn-default']) !!} 

An array of parameters with a class is optional, in this case it sets the style for the Bootstrap 3 button.

+17
Jul 05 '14 at 19:42
source share

In 5.1, I could only make it work.

 <a href="{{ URL::previous() }}" class="btn btn-default">Back</a> 
+13
Apr 14 '16 at 14:35
source share

Indeed, using {{ URL:previous() }} does work, but if you use the same route to display multiple views, it will return you to the first endpoint of that route.

In my case, I have a named route, which, based on a parameter selected by the user, can display 3 different views. Of course, I have a default case for the first input of this route, when the user has not yet selected any option.

When I use the URL:previous() , Laravel returns me to the default view, even if the user selects another option. Only using javascript inside the button I executed to get back to the correct view:

 <a href="javascript:history.back()" class="btn btn-default">Voltar</a> 

I tested this on Laravel 5.3, just for clarification.

+13
Mar 31 '17 at 16:49
source share

One of the following methods will solve your problem.

 URL::previous() URL::back() 

Other

 URL::current() 
+1
May 26 '18 at 12:40
source share

Any idea for a back button with previous page form data in a multi-step form?

0
Feb 03 '19 at 21:58
source share

Since this post is still the best Google search result for the โ€œlaravel back buttonโ€, for anyone using Laravel 5.8 , here's what works:

 <a href="{{ url()->previous() }}">Back</a> 
-one
Aug 23 '19 at 1:39 on
source share



All Articles