Laravel - Localhost 重定向你太多次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37888978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - Localhost redirected you too many times
提问by Akmal Arzhang
We had one app developed almost a year ago and here I'm facing a problem.
After signing in the chrome says: The localhost page isn't working, localhost redirected you too many times.
.
And the problem lies in this piece of code at controller that while I remove it, it works fine. I couldn't figure out what is wrong with this.
我们大约一年前开发了一个应用程序,在这里我遇到了一个问题。登录 chrome 后说:The localhost page isn't working, localhost redirected you too many times.
. 问题在于控制器的这段代码,当我删除它时,它工作正常。我无法弄清楚这有什么问题。
if(Auth::check()){
$usertype=usertype::where('uid','=',Auth::user()->id)->first();
if(isset($usertype)){
if($usertype->type==1){
$shopcatagory=shopcatagory::where('sid','=',Auth::user()->id)->first();
$shopsubcatagory=shopsubcatagory::where('sid','=',Auth::user()->id)->first();
$shopphone=shopphone::where('sid','=',Auth::user()->id)->first();
$shopaddress=shopaddress::where('sid','=',Auth::user()->id)->first();
$shopplace=shopplace::where('sid','=',Auth::user()->id)->first();
if(!isset($shopaddress) || !isset($shopcatagory) || !isset($shopsubcatagory) || !isset($shopphone) || !isset($shopplace)){
return Redirect::action('HomeController@accountinfo',Auth::user()->id);
}
}
else if($usertype->type==3){
$shopphone=shopphone::where('sid','=',Auth::user()->id)->first();
$shopaddress=shopaddress::where('sid','=',Auth::user()->id)->first();
$shopplace=shopplace::where('sid','=',Auth::user()->id)->first();
if(!isset($shopaddress) || !isset($shopphone) || !isset($shopplace)){
return Redirect::action('HomeController@accountinfo',Auth::user()->id);
}
}
else if($usertype->type == 2){
$userinterests=userinterests::where('uid','=',Auth::user()->id)->first();
if(!isset($userinterests)){
return Redirect::action('HomeController@interests');
}
}
}
}
回答by jszobody
In this big Auth::check
block, there are two different routes that you are potentially redirecting to: accountinfo
and interests
.
在这个大块中Auth::check
,您可能重定向到两条不同的路由:accountinfo
和interests
。
So if you are getting stuck in an infinite loop, then it sounds like this very code is running on one (or both) of those very routes!
因此,如果您陷入无限循环,那么听起来这段代码正在其中一个(或两个)路径上运行!
Track that down, make sure that neither of those two routes include this Auth::check
code with the redirects.
跟踪它,确保这两条路由都没有Auth::check
在重定向中包含此代码。