Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Redirect back to the same page where the request comes from

In Laravel 4, I want to redirect the user back to the page from where the request came. For example, a user tries to update his profile so edits the profile and hits SAVE. In controller I do the update and normally I would do Redirect::to('profile')->with('message','Profile saved!'). But what I want is to simply redirect it back with message. May be something like Redirect::back()->with('message','Operation Successful !') if this is available. I want it as it is more generic and I can use it anywhere.

like image 824
Abhay PS Avatar asked Jan 22 '14 18:01

Abhay PS


People also ask

How do I redirect a previous URL?

There are two approaches used to redirect the browser window back. Approach 1: Using history. back() Method: The back() method of the window. history object is used to go back to the previous page in the current session history.

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


1 Answers

Yes this is available:

return Redirect::back()->with('message','Operation Successful !'); 

But since this is a redirected request, you have to access the message by using:

echo Session::get('message'); 
like image 138
Antonio Carlos Ribeiro Avatar answered Sep 30 '22 20:09

Antonio Carlos Ribeiro