コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }