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

getAttributeValue() public method

Get a plain attribute (not a relationship).
public getAttributeValue ( string $key ) : mixed
$key string
return mixed
    public function getAttributeValue($key)
    {
        $value = $this->getAttributeFromArray($key);
        // If the attribute has a get mutator, we will call that then return what
        // it returns as the value, which is useful for transforming values on
        // retrieval from the model to a form that is more useful for usage.
        if ($this->hasGetMutator($key)) {
            return $this->mutateAttribute($key, $value);
        }
        // If the attribute exists within the cast array, we will convert it to
        // an appropriate native PHP type dependant upon the associated value
        // given with the key in the pair. Dayle made this comment line up.
        if ($this->hasCast($key)) {
            return $this->castAttribute($key, $value);
        }
        // If the attribute is listed as a date, we will convert it to a DateTime
        // instance on retrieval, which makes it quite convenient to work with
        // date fields without having to create a mutator for each property.
        if (in_array($key, $this->getDates()) && !is_null($value)) {
            return $this->asDateTime($value);
        }
        return $value;
    }

Usage Example

Example #1
0
 public function getAttributeValue($key)
 {
     $value = parent::getAttributeValue($key);
     if (in_array($key, array_keys($this->postgresifyTypes))) {
         if (!is_null($value)) {
             return PostgresifyTypeTransformer::transform($key, $value, $this->postgresifyTypes[$key]);
         }
     }
     return $value;
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::getAttributeValue
Model