【发布时间】:2016-06-17 19:23:45
【问题描述】:
我们大约一年前开发了一个应用程序,但我遇到了一个问题。
登录 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');
}
}
}
}
【问题讨论】:
-
除了代码如此粘在一起难以阅读之外,很明显存在无限循环。只需通读那个卷心菜并确定哪些部分可能会失败以及您是否处理了该失败(从您制作的沙拉的一瞥中,您的代码可能会在很多地方失败,因此不值得写一个答案来突出显示每个部分)。
-
发布此内容时,我也有同样的想法,因为这是我们第一次使用 Laravel,现在我无法更改所有内容以使其变得更好。很明显这是一个意大利面条代码,我看到这个感觉很糟糕。
-
@jszobody 将其作为答案发布,以便我将其作为正确答案进行检查。是的,这些检查在那里运行,删除它们解决了问题。
-
@AkmalArzhang 完成!