Dimsav\Translatable\Translatable::getAttribute PHP Метод

getAttribute() публичный Метод

public getAttribute ( string $key ) : mixed
$key string
Результат mixed
    public function getAttribute($key)
    {
        if (str_contains($key, ':')) {
            list($key, $locale) = explode(':', $key);
        } else {
            $locale = $this->locale();
        }
        if ($this->isTranslationAttribute($key)) {
            if ($this->getTranslation($locale) === null) {
                return null;
            }
            // If the given $key has a mutator, we push it to $attributes and then call getAttributeValue
            // on it. This way, we can use Eloquent's checking for Mutation, type casting, and
            // Date fields.
            if ($this->hasGetMutator($key)) {
                $this->attributes[$key] = $this->getTranslation($locale)->{$key};
                return $this->getAttributeValue($key);
            }
            return $this->getTranslation($locale)->{$key};
        }
        return parent::getAttribute($key);
    }