2016-06-01 90 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! 
}