Laravel 5 Laravel 5-重定向()->;身份验证后的预期()不适用于预期
我使用的是Laravel5.0的默认postAuth和默认身份验证。由于某些原因,Laravel 5 Laravel 5-重定向()->;身份验证后的预期()不适用于预期,laravel-5,Laravel 5,我使用的是Laravel5.0的默认postAuth和默认身份验证。由于某些原因,redirect()->destined()不起作用!调试Session::get('url.designed')显示了一些古怪的东西,但不知道这是否正常 我注销,然后尝试访问http://localhost:3000/updates,这是一条有效的路线。它正确地将我发送到/auth/login,但一旦我登录,它总是将我发送到/home。在AuthenticatesAndRegistersUserstrait中,我
redirect()->destined()
不起作用!调试Session::get('url.designed')
显示了一些古怪的东西,但不知道这是否正常
我注销,然后尝试访问http://localhost:3000/updates
,这是一条有效的路线。它正确地将我发送到/auth/login
,但一旦我登录,它总是将我发送到/home
。在AuthenticatesAndRegistersUsers
trait中,我将其放入:
if ($this->auth->attempt($credentials, $request->has('remember')))
{
dd(\Session::get('url.intended'));
return redirect()->intended($this->redirectPath());
}
dd()
显示了正确的预期路径,但末尾有一堆垃圾
“//本地主机:3000/更新%3C/span%3E”
执行dd(redirect()->destinated())
会暴露出它试图转到那个奇怪的url:
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
}
更新2
我决定停止使用Browsersync,我认为这是导致
的原因,并开始在常规vhost url上进行调试。在illighted\Routing\Redirector
的designed()
方法中进行调试,一切看起来似乎都应该正常工作
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
}
与我预期的原始返回重定向()->($this->redirectPath())
完全一样。硬编码路径,return redirect()->designed(“/updates”)
,将我发送到/updates
。这让我觉得默认路径参数导致了问题,但转储整个响应看起来很合理。我完全不知所措。一定有我遗漏的东西。如果你urldecode()
你想要的路线,你会得到localhost:3000/更新。检查链接上的href
属性。找出结束span标记的来源。你能展示一下你的中间件吗?它会将你重定向到登录页面?@BrokenBinary我不会点击任何链接,而是直接指向url。@DanielAntos用中间件更新了,这就是LaravelIt附带的是我自己的愚蠢中间件!
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'));
}