public function getAttribute($key, $model = false)
    {
        if (!$key) {
            return;
        }

        if (!$model) {
            $model = $this->model;
        }

        $formattedKey = str_replace('.', '_', $key);

        if ($this->hasGetAccessor($formattedKey)) {
            $method = 'get'.Str::studly($formattedKey).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasGetAccessor($key)) {
            $method = 'get'.Str::studly($key).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasRelatedKey($key, $model)) {
            return $this->relatedKey($key, $model);
        }

        return $model->getAttribute($key);
    }
public function getAttribute($key, $model = false)
    {
        if (!$key) {
            return;
        }

        if (!$model) {
            $model = $this->model;
        }

        $formattedKey = str_replace('.', '_', $key);

        if ($this->hasGetAccessor($formattedKey)) {
            $method = 'get'.Str::studly($formattedKey).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasGetAccessor($key)) {
            $method = 'get'.Str::studly($key).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasRelatedKey($key, $model)) {
            return $this->relatedKey($key, $model);
        }

        return $model->getAttribute($key);
    }
public function getAttribute ( $ key , $ model = false ) { if ( ! $ key ) { return ; } if ( ! $ model ) { $ model = $ this -> model ; } $ formattedKey = str_replace ( '.' , '_' , $ key ) ; if ( $ this -> hasGetAccessor ( $ formattedKey ) ) { $ method = 'get' . Str :: studly ( $ formattedKey ) . 'Attribute' ; return $ this -> { $ method } ( $ model ) ; } if ( $ this -> hasGetAccessor ( $ key ) ) { $ method = 'get' . Str :: studly ( $ key ) . 'Attribute' ; return $ this -> { $ method } ( $ model ) ; } if ( $ this -> hasRelatedKey ( $ key , $ model ) ) { return $ this -> relatedKey ( $ key , $ model ) ; } return $ model -> getAttribute ( $ key ) ; }
Gets an Attribute by the provided key
on either the current model or a provided model instance.

@param string $key
@param mixed  $model

@return mixed
Gets an Attribute by the provided key on either the current model or a provided model instance .