[英]Laravel get redirect URL
我在获取Laravel URL时遇到问题。
我有一个页面,如果用户未登录,则会将用户重定向到错误的url,并且显示错误。
我正在使用redirect()->intended($this->redirectPath());
为了让用户在登录后回到页面上的位置,所以我不得不以某种方式编写代码来检查什么是重定向URL,以及是否是会产生错误的URL,
我知道什么是URL,它必须将用户重定向到我需要设置的另一个URL。
我尝试了采用$this->redirectPath() == 'here goes the url'
就像redirect()->intended($this->redirectPath()) == 'again url here'
但是没有任何效果。
尝试这个:
return Redirect::intended('here goes the url');
要么
return Redirect::intended();
purposes intended()
检查会话索引url.intended是否存在并默认重定向到它,否则重定向到$ default ='/',它可以被覆盖。
您必须了解redirect()->intended()
实际作用。
它会寻找一个名为url.intended
的会话变量,就像session()->pull('url.intended')
(请注意, pull()
将在此调用后删除该变量,这很方便,因为您通常只需要一次使用此变量) 。
当前仅在调用redirect()->guest('/yourpath')
时设置此变量(它将您的当前URL设置为url.intended
),除非您使用session()->put('url.intended')
以自己的逻辑手动设置它session()->put('url.intended')
。
因此,最明显的使用方法是使用redirect()->guest('/login')
,然后在用户成功登录后,您可以使用redirect()->intended()
(无参数)进行重定向用户返回到最初将他发送到登录页面的页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.