0

I have a parent model ParentModel, and in it I want to check if ChildModel has a relation, say, user or not.

I try something like:

$relation = "user";
if (isset($this->$relation)){
//    dosomething
}

but the condition is always false even when the relation actually exists.

I know it is a naive question.... :( okay, sue me, I can't find the answer!

Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56

2 Answers2

0

Try:

  $relation = "user";
  if (!empty($this->$relation)){
   //    dosomething
  }
CreatoR
  • 1,654
  • 10
  • 14
0

I find an answer

isset($this->relations()[$relation])
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56