Redirect url to previous page in laravel

2020-06-07 04:39发布

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.

5条回答
Root(大扎)
2楼-- · 2020-06-07 04:48

Inside your template file you can just use:

{{ url()->previous() }}
查看更多
我只想做你的唯一
3楼-- · 2020-06-07 04:56

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!');
查看更多
够拽才男人
4楼-- · 2020-06-07 04:56

you should this methods:

return calling controller:

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

return calling url:

return redirect('home/dashboard');

REDIRECTS LARAVEL 5.2

查看更多
萌系小妹纸
5楼-- · 2020-06-07 04:59

You have a global back function:

return back();
查看更多
Lonely孤独者°
6楼-- · 2020-06-07 05:07

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

查看更多
登录 后发表回答