getRelationValue() public method

Get a relationship.
public getRelationValue ( string $key ) : mixed
$key string
return mixed
Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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);
     }
 }
Example #3
0
File: Model.php Project: jjiko/blog
 /**
  * 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;
 }