Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect url to previous page in laravel

How to redirect to previous page in laravel5.2 like URI Referrer in php.

I've tried $request->url(); but it gets the current url.

I've a form and list pages.There are many lists that redirects to form.but I want to go to that specific page after submit.

For Ex:There are a Project and Client list. If I go to form from project then it should go to project and if I go to form from client list It should go to client list page after submitting a form.

like image 436
Nikhil Radadiya Avatar asked Jul 20 '16 13:07

Nikhil Radadiya


People also ask

How do I redirect back to original url after successful login in laravel?

You can apply this filter to the routes that need authentication. Route::filter('auth', function() { if (Auth::guest()) { return Redirect::guest('login'); } }); What this method basically does it's to store the page you were trying to visit and it is redirects you to the login page. return Redirect::intended();

How would you redirect back to a controller action?

Redirect to a Controller Action The last piece of the puzzle is that you can redirect to a specific Method of a specific Controller, no matter what its Route or URL is – use method action(): return redirect()->action('App\Http\Controllers\BooksController@index');


2 Answers

You should use return redirect()->back();

like image 76
AntoineB Avatar answered Sep 22 '22 13:09

AntoineB


Inside your template file you can just use:

{{ url()->previous() }} 
like image 37
Gavin Avatar answered Sep 22 '22 13:09

Gavin