laravel检查模型的字段是否为空

I have a model's field like this:

$xmlDocument->masterInformation->nextPage->prefix

this field is not required.

I want to check if that field is empty or not

I do this:

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

but the if statement is never becomming true though when I echo that field, i got data.

what am i missing please?

Update like this,

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