Search code examples
laravelpropertiesexists

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))

Solution

  • Try isset php function.

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


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