如何将用户重定向到单击编辑按钮的上一页 [英] How to redirect a user to a previous page where the edit button was clicked

查看:29
本文介绍了如何将用户重定向到单击编辑按钮的上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个索引页面,其中显示了所有模型,当您单击编辑"时,您进入编辑页面,在更改某些内容后,单击更新",您将被重定向到索引,在那里一切正常.

I have an index page where all the models are shown and when you click edit you go to edit page and after you change something you click update and you will be redirected to index, all fine there.

现在我已经进入了显示视图,并且在显示视图中我单击了相同的编辑按钮以转到编辑页面,当您单击更新"时,您当然会被重定向到索引页面,而我不希望那样.我想将用户重定向到单击编辑"按钮的页面.

And now i have made a show view and in show view i made the same edit button to go to edit page and when you click update of course you will be redirected of to the index page and i don't want that. I want to redirect user to the page where the EDIT button was clicked.

我如何将用户重定向到他们实际单击编辑按钮的页面?

How can i redirect users to the page where they actually clicked the edit button?

推荐答案

您可以将会话中的URL保留为

You can keep URL in session to go two pages back in Laravel:

$links = session->has('links') ? session('links') : []; // Get data from session
array_unshift($links, $_SERVER['REQUEST_URI']); // Add current URI to an array
session(compact('links')); // Save an array to session

然后您可以返回2页:

return redirect(session('links')[2]);

这篇关于如何将用户重定向到单击编辑按钮的上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆