我正在使用Laravel 5.0的默认postAuth,默认身份验证。出于某种原因,redirect()->intended()
不起作用!调试Session::get('url.intended')
会显示一些时髦的东西,但不知道它是否正常。
我退出,然后尝试访问http://localhost:3000/updates
,这是一条有效路线。它正确地将我发送到/auth/login
,但是一旦我登录它总是将我发送到/home
。在AuthenticatesAndRegistersUsers
特征中,我将其放入:
if ($this->auth->attempt($credentials, $request->has('remember')))
{
dd(\Session::get('url.intended'));
return redirect()->intended($this->redirectPath());
}
dd()
显示正确的预期路径,但最后有一堆垃圾。
“//本地主机:3000 /更新%3C /跨度%3E”
执行dd(redirect()->intended())
暴露它正试图转到那个奇怪的网址:
RedirectResponse {#344 ▼
#request: Request {#37 ▶}
#session: Store {#304 ▶}
#targetUrl: "//localhost:3000/updates%3C/span%3E"
+headers: ResponseHeaderBag {#346 ▶}
#content: """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=//localhost:3000/updates" />
<title>Redirecting to //localhost:3000/updates</title>%3C/span%3E
</head>
<body>
Redirecting to <a href="//localhost:3000/updates">//localhost:3000/updates</a>.%3C/span%3E
</body>
</html>"""
#version: "1.0"
#statusCode: 302
#statusText: "Found"
#charset: null
}
我在许多其他路线上尝试了这个并且结果相同。我本可以发誓这是按预期工作的。任何想法为什么会停止?
更新
这是Authenticate.php
中间件,未经Laravel修改:
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
return response('Unauthorized.', 401);
}
else
{
return redirect()->guest('auth/login');
}
}
return $next($request);
}
更新2
我决定停止使用Browsersync,我认为这是</span>
的原因,并开始在常规vhost网址上进行调试。在Illuminate\Routing\Redirector
的{{1}}方法中进行调试,一切看起来都应该仍然正常。
intended()
在if ($this->auth->attempt($credentials, $request->has('remember')))
{
dd(redirect()->intended($this->redirectPath()));
return redirect()->intended($this->redirectPath());
}
中执行该操作仍会显示出看似正确的答案:
postLogin()
这样做:
RedirectResponse {#346 ▼
#request: Request {#37 ▶}
#session: Store {#288 ▶}
#targetUrl: "http://sum.dev/updates"
+headers: ResponseHeaderBag {#348 ▼
#computedCacheControl: array:1 [▶]
#cookies: []
#headerNames: array:3 [▶]
#headers: array:3 [▼
"cache-control" => array:1 [▶]
"date" => array:1 [▶]
"location" => array:1 [▼
0 => "http://sum.dev/updates"
]
]
#cacheControl: []
}
#content: """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=http://sum.dev/updates" />
<title>Redirecting to http://sum.dev/updates</title>
</head>
<body>
Redirecting to <a href="http://sum.dev/updates">http://sum.dev/updates</a>.
</body>
</html>"""
#version: "1.0"
#statusCode: 302
#statusText: "Found"
#charset: null
}
完全按照我原来if ($this->auth->attempt($credentials, $request->has('remember')))
{
return redirect(\Session::get('url.intended'));
}
的方式工作。对路径进行硬编码return redirect()->intended($this->redirectPath())
会将我发送到return redirect()->intended('/updates')
。它让我觉得默认路径参数导致了问题,但是整个响应的转储看起来很合理。我完全不知所措。必须有一些我想念的东西。