public function __get($name) { if ($this->model->hasAttribute($name)) { return $this->model->getAttribute($name); } if (isset($this->relations[$name])) { return $this->relations[$name]; } foreach ($this->relations as $model) { if ($model->hasAttribute($name)) { return $model->getAttribute($name); } } return parent::__get($name); }