Illuminate\Database\Eloquent\Model::getAttribute PHP Method

getAttribute() public method

Get an attribute from the model.
public getAttribute ( string $key ) : mixed
$key string
return mixed
    public function getAttribute($key)
    {
        if (!$key) {
            return;
        }
        if (array_key_exists($key, $this->attributes) || $this->hasGetMutator($key)) {
            return $this->getAttributeValue($key);
        }
        if (method_exists(self::class, $key)) {
            return;
        }
        return $this->getRelationValue($key);
    }

Usage Example

 /**
  * @param Model $oModel
  * @return array
  */
 protected function resolveModelToArray(Model $oModel)
 {
     /** @var Key $oKey */
     $oKey = $oModel->getAttribute("key");
     /** @var Locale $oLocale */
     $oLocale = $oModel->getAttribute("locale");
     $aReturn = [$oModel->getKeyName() => $oModel->getKey(), "key" => $oKey ? $oKey->getAttribute(Key::COLUMN_NAME) : null, "locale" => $oLocale ? $oLocale->getAttribute(Locale::COLUMN_CODE) : null, Message::COLUMN_TEXT => $oModel->getAttribute(Message::COLUMN_TEXT)];
     return $aReturn;
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::getAttribute
Model