Laravel检查属性存在

Igo*_*iuk 1 properties exists laravel

如何$this->team->playerAssignment->player更合理地检查现有财产?现在,我像这样检查它:

if ($this->team)
   if (($this->team->playerAssignment))
      if (($this->team->playerAssignment->player))
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试使用isset php函数。

isset —确定是否设置了变量并且不为NULL


if(isset($this->team->playerAssignment->player)){

}
Run Code Online (Sandbox Code Playgroud)