Redirect url to previous page in laravel

PhpLaravel 5.2

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

Inside your template file you can just use:

{{ url()->previous() }}

Solution 3 - Php

You have a global back function:

return back();

Solution 4 - Php

Thank You for answers. I've got it now.

set the hidden variable in blade to get previous page url using

{{  Form::hidden('url',URL::previous())  }}

after that get it by $request->input('url'); in controller,Then redirect it.

return redirect($url)->with('success', 'Data saved successfully!');

Solution 5 - Php

To redirect from template You should use

{{ url()->previous() }}

To redirect from the controller you should use

return redirect()->back(); 

or Just

 return back();

Solution 6 - Php

You can redirect back to previous page on Laravel Blade using

{{ url()->previous() }}

Example below:

<a  href="{{ url()->previous() }}">
    <i class="fa fa-arrow-circle-o-left"></i>
    <span>Back</span>
</a>

Solution 7 - Php

you should this methods:

return calling controller:

return redirect()->action('classcontroller@fuction');

return calling url:

return redirect('home/dashboard');

REDIRECTS LARAVEL 5.2

Solution 8 - Php

As the description of your problem, the simple solution is, you have to use the below code in the controller,

return back();

or,

return redirect()->back();

If you want to get the link from where you came from, You can apply the following code in the blade template,

{{ url()->previous() }}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNikhil RadadiyaView Question on Stackoverflow
Solution 1 - PhpAntoineBView Answer on Stackoverflow
Solution 2 - PhpGavinView Answer on Stackoverflow
Solution 3 - Phpka_linView Answer on Stackoverflow
Solution 4 - PhpNikhil RadadiyaView Answer on Stackoverflow
Solution 5 - PhpMannu saraswatView Answer on Stackoverflow
Solution 6 - PhpChime EmmanuelView Answer on Stackoverflow
Solution 7 - PhpEl MickeView Answer on Stackoverflow
Solution 8 - PhpJaiedView Answer on Stackoverflow