2014-09-04 155 views
0

我有一個模型的領域是這樣的:不需要laravel檢查是否爲空

$xmlDocument->masterInformation->nextPage->prefix 

這一領域。

我要檢查該字段爲空或不

我這樣做:

if(trim($xmlDocument->masterInformation->nextPage->prefix)){ 
      $data['NextPage']['prefix'] = $xmlDocument->masterInformation->nextPage->prefix; 
     } 

但儘管當我echo該字段if聲明從未真正becomming,我得到的數據。

我在想什麼?

回答

1

更新這個樣子,

if(trim($xmlDocument->masterInformation->nextPage->prefix) != '') 
+0

我只是想你的解決方案,目前仍是如果statment不點火,但是else語句射擊 – 2014-09-04 09:13:03

+0

沒有任何遺憾的if語句現在射擊,但'prefix'陣列中沒有顯示,請問爲什麼?你想要更多的代碼嗎? – 2014-09-04 09:14:01

+1

現在我發現了問題+1我會在系統允許時接受你的答案,非常感謝 – 2014-09-04 09:15:32