Illuminate\Database\Eloquent\Model::relationLoaded PHP Method

relationLoaded() public method

Determine if the given relation is loaded.
public relationLoaded ( string $key ) : boolean
$key string
return boolean
    public function relationLoaded($key)
    {
        return array_key_exists($key, $this->relations);
    }

Usage Example

Example #1
0
 /**
  * Get property simple value by name.
  *
  * @param string $key
  *
  * @return mixed|Collection
  */
 public function getValue($key)
 {
     $value = $this->getPropertyValue($key);
     $property = $this->getProperties()->get($key);
     if ($value instanceof Collection) {
         /* @var MultipleCollection $collection
          * @var Collection $value
          */
         $collection = $this->entity->relationLoaded($key) ? $this->entity->getRelation($key) : null;
         if ($collection === null) {
             $collection = new MultipleCollection($this, $property);
         }
         $collection->setValues($value->map(function (Value $value) {
             return $value->getAttributeValue('value');
         }));
         return $collection;
     } elseif ($value instanceof Value) {
         return $value->getAttributeValue('value');
     }
 }
Model