public function getRelation($reset = false) { if (!$this->relation || $reset) { $this->relation = Relation::where('entity_id', $this->id)->where('entity_type', get_class($this))->first(); } return $this->relation; }
public function getChildren() { $childrenList = []; $childrenRelations = Relation::where('parent_id', $this->entity_id)->where('parent_type', $this->entity_type)->get(); foreach ($childrenRelations as $childrenRelation) { $children = new $childrenRelation->entity_type(); $childrenList[] = $children::find($childrenRelation->entity_id); } return $childrenList; }