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.
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.
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();
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With