/** * Get a relationship. * * @param string $key * @return mixed */ public function getRelationValue($key) { $return = parent::getRelationValue($key); if (is_null($return)) { $return = $this->getRelationshipFromMethod($key); } return $return; }
/** * Special function to access $model->relation, like $user->groups, etc * * @param string $key * * @return mixed */ public function getRelationValue($key) { if ($results = $this->relations[$key] ?? null) { return $results; } elseif ($relation = $this->dynamicRelation($key)) { return $this->relations[$key] = $relation->getResults(); } else { return parent::getRelationValue($key); } }
/** * Get the relation value setting the connection name * * @param string $key * @return mixed */ public function getRelationValue($key) { $relation = parent::getRelationValue($key); if ($relation instanceof Collection) { $relation->each(function ($model) { $this->setRelationConnection($model); }); return $relation; } $this->setRelationConnection($relation); return $relation; }