public function __get($key)
{
// If the relation has been loaded already, return it
if (array_key_exists($key, $this->relations)) {
return $this->relations[$key];
}
// If the model supports the locale, load and return it
if (in_array($key, $this->getAvailable())) {
$relation = $this->hasOne($this->getLangClass())->whereLang($key);
if ($relation->getResults() === null) {
$relation = $this->hasOne($this->getLangClass())->whereLang(Config::get('polyglot::fallback'));
}
return $this->relations[$key] = $relation->getResults();
}
// If the attribute is set to be automatically localized
if ($this->polyglot) {
if (in_array($key, $this->polyglot)) {
/**
* If query executed with join and a property is already there
*/
if (isset($this->attributes[$key])) {
return $this->attributes[$key];
}
$lang = Lang::getLocale();
return $this->{$lang} ? $this->{$lang}->{$key} : null;
}
}
return parent::__get($key);
}