2016-06-01 126 views
0

这应该是简单的,但在我if块某种原因代码尽管它解析为false和它让我很不爽......我在这种情况下user_id是2的事实正在执行。Laravel 5个简单的比较失败

$note = Notification::where("user_id",Auth::user()->id)->first(); 
$wall = $note->pluck('wall'); 
if($wall != 0) 
{ 
//This code is executing! 
} 
else{ 
    array_push($data,"Your First Time!"); 
    //This code is not! 
} 

正如你所看到的,我的$墙壁应该是零,所以我不明白为什么$wall != 0运行。

enter image description here

+0

确定'$ wall'确实'0'?试试'var_dump($ wall);'在你之前'if(..){..' – Darren

+0

我不认为你需要使用pluck。您已通过使用 - > first()检索模型。简单地做$ note-> wall – Brett

+0

@Darren谢谢,它给了我'string(3)“130”',所以出于某种原因它读取了错误的'user_id' ...为什么会这样呢? –

回答

2

删除勇气

$note = Notification::where("user_id",Auth::user()->id)->first(); 
$wall = $note->wall; //This changed 
if($wall != 0) 
{ 
//This code is executing! 
} 
else{ 
    array_push($data,"Your First Time!"); 
    //This code is not! 
}