首页 > 解决方案 > Laravel 获取重定向地址

问题描述

我在获取 Laravel URL 时遇到问题。

我有一个页面,如果用户未登录,它将用户重定向到错误的 url 并给出错误。

redirect()->intended($this->redirectPath());用来让用户在登录后回到他在页面上的位置,所以我必须以某种方式编写代码来检查什么是重定向 URL,如果它是会给出错误的 URL,

我知道 URL 是什么,它必须将用户重定向到我需要设置的另一个 URL。

我尝试了不同的方法 $this->redirectPath() == 'here goes the url'

和喜欢 redirect()->intended($this->redirectPath()) == 'again url here'

但没有任何效果。

标签: phplaravel

解决方案


尝试这个:

return Redirect::intended('here goes the url');

或者

return Redirect::intended();

intended()检查会话索引 url.intended 是否存在并默认重定向到它,否则重定向到可以覆盖的 $default='/'。


推荐阅读