Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel check property exist

How I can check existing property $this->team->playerAssignment->player in more rational way? Now I check it like this:

if ($this->team)
   if (($this->team->playerAssignment))
      if (($this->team->playerAssignment->player))
like image 877
Igor Ostapiuk Avatar asked Sep 19 '17 13:09

Igor Ostapiuk


1 Answers

Try isset php function.

isset — Determine if a variable is set and is not NULL


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

}
like image 179
Nurlan Nuriyev Avatar answered Sep 19 '22 17:09

Nurlan Nuriyev