src/Models/Traits/TranslatedAttributes.php
public function getAttribute($key, $translated = false)
    {
        if (false === $translated) {
            return parent::getAttribute($key);
        }
        
        $defaultLanguage = Session::get('default_language');
        $languageId = request()->get('language_id', $defaultLanguage->id);

        if (in_array($key, $this->getTranslatedAttributes())
            && $defaultLanguage->id != $languageId
        ) {
            $translatedModel = $this->translations()
                ->whereLanguageId($languageId)
                ->first();
            if ($translatedModel === null) {
                return null;
            }
            return $translatedModel->attributes[$key];
        }
        
        return parent::getAttribute($key);
    }
public function getAttribute($key, $translated = false)
    {
        if (false === $translated) {
            return parent::getAttribute($key);
        }
        
        $defaultLanguage = Session::get('default_language');
        $languageId = request()->get('language_id', $defaultLanguage->id);

        if (in_array($key, $this->getTranslatedAttributes())
            && $defaultLanguage->id != $languageId
        ) {
            $translatedModel = $this->translations()
                ->whereLanguageId($languageId)
                ->first();
            if ($translatedModel === null) {
                return null;
            }
            return $translatedModel->attributes[$key];
        }
        
        return parent::getAttribute($key);
    }
public function getAttribute ( $ key , $ translated = false ) { if ( false === $ translated ) { return parent :: getAttribute ( $ key ) ; } $ defaultLanguage = Session :: get ( 'default_language' ) ; $ languageId = request ( ) -> get ( 'language_id' , $ defaultLanguage -> id ) ; if ( in_array ( $ key , $ this -> getTranslatedAttributes ( ) ) && $ defaultLanguage -> id != $ languageId ) { $ translatedModel = $ this -> translations ( ) -> whereLanguageId ( $ languageId ) -> first ( ) ; if ( $ translatedModel === null ) { return null ; } return $ translatedModel -> attributes [ $ key ] ; } return parent :: getAttribute ( $ key ) ; }
Get the Attribute of an model
@param string $key
@return mixed
Get the Attribute of an model