Php laravel检查模型是否为';s文件是否为空

Php laravel检查模型是否为';s文件是否为空,php,laravel,Php,Laravel,我有一个这样的模型场: $xmlDocument->masterInformation->nextPage->prefix 此字段不是必需的 我想检查该字段是否为空 我这样做: if(trim($xmlDocument->masterInformation->nextPage->prefix)){ $data['NextPage']['prefix'] = $xmlDocument->masterInformation->

我有一个这样的模型场:

$xmlDocument->masterInformation->nextPage->prefix
此字段不是必需的

我想检查该字段是否为空

我这样做:

if(trim($xmlDocument->masterInformation->nextPage->prefix)){
            $data['NextPage']['prefix'] = $xmlDocument->masterInformation->nextPage->prefix;
        }
但是
if
语句从来都不是真的,尽管当我
echo
该字段时,我得到了数据

请问我遗漏了什么?

像这样更新

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

我刚刚尝试了您的解决方案,但if语句仍然没有启动,但是else语句正在启动不,不,对不起,if语句现在正在启动,但是数组中的
前缀
项没有显示,为什么?你想要更多的代码吗?现在我发现问题+1,如果系统允许,我会接受你的答案,非常感谢