Get the value of an attribute using its mutator for array conversion.

@param  string $key
@param  mixed  $value
@return mixed
355533
protected function mutateAttributeForArray($key, $value)
    {
        $value = $this->mutateAttribute($key, $value);

        return $value instanceof ArrayableInterface ? $value->toArray() : $value;
    }
1140636
protected function castAttribute($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }

        switch ($this->getCastType($key)) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            case 'collection':
                return new BaseCollection($this->fromJson($value));
            case 'date':
            case 'datetime':
                return $this->asDateTime($value);
            case 'timestamp':
                return $this->asTimeStamp($value);
            default:
                return $value;
        }
    }
543846
protected function getFormattedValue(Model $model, string $key, $value)
    {
        // Apply defined get mutator
        if ($model->hasGetMutator($key)) {
            return $model->mutateAttribute($key, $value);
        }

        // Cast to native PHP type
        if ($model->hasCast($key)) {
            return $model->castAttribute($key, $value);
        }

        // Honour DateTime attribute
        if ($value !== null && in_array($key, $model->getDates(), true)) {
            return $model->asDateTime($value);
        }

        return $value;
    }
308138
protected function mutateAttribute($key, $value)
    {
        $TitleCase = ucwords(str_replace(['-', '_'], ' ', $key));
        $StudlyCase = str_replace(' ', '', $TitleCase);

        return $this->{'get'.$StudlyCase.'Attribute'}($value);
    }
117320
protected function getAttributeValue($key)
	{
		$value = parent::getAttributeValue($key);

		if ($this->isCastableAttribute($key))
		{
			$value = $this->castAttribute($key, $value);
		}

		return $value;
	}
580206
public function getApiKeyAttribute($value)
  {
    if ($value == null) $this->update(['api_key' => $key = Hash::random(25)]);
    return $value ?? $key;
  }
625704
public function setAttribute($key, $value = null)
    {
        if(is_array($key))
        {
            foreach($key as $item => $value) {
                if(strrpos($item, '[]') == ($itemLength = strlen($item) - 2)) {
                    $this->attributes[substr($item, 0, $itemLength)][] = $value;
                } else {
                    $this->attributes[$item] = $value;
                }
            }
        }
        else
        {
            if(strrpos($key, '[]') == ($keyLength = strlen($key) - 2)) {
                $this->attributes[substr($key, 0, $keyLength)][] = $value;
            } else {
                $this->attributes[$key] = $value;
            }
        }

        return $this;
    }
1235721
public function setAttribute($key, $value)
    {
        if (in_array($key, $this->getTranslatable())) {
            $translation = $this->translateOrNew($this->getLocale());

            $translation->$key = $value;

            $this->translationCache[$this->getLocale()] = $translation;

            return $translation;
        }

        return parent::setAttribute($key, $value);
    }
533027
public function attr($key, $value = null)
    {
        if(is_array($key))
        {
            foreach($key as $k => $val)
                $this->attributes[$k] = $val;

            return $this;
        }
        elseif($value === null)
        {
            $this->attributeString[] = $key;

            return $this;
        }

        if($key == 'class')
            return $this->addClass($value);

        $this->attributes[$key] = $value;

        return $this;
    }
397942
public function getValueAttribute($value)
    {
        if (!is_array($value)) {
            $decodedValue = json_decode($value, true);
        }

        //Not a JSON string.
        if (!empty($value) && empty($decodedValue)) {
            $decodedValue = $value;
        }

        return $decodedValue;
    }
247025
public function getAttribute($key)
    {
        $inAttributes = array_key_exists($key, $this->attributes);

        // If the key references an attribute, we can just go ahead and return the
        // plain attribute value from the model. This allows every attribute to
        // be dynamically accessed through the _get method without accessors.
        if ($inAttributes || $this->hasGetMutator($key)) {
            return $this->getAttributeValue($key);
        }

        $inPaths = array_key_exists($key, $this->paths);

        // If the key references an path attribute, we can just go ahead and return the
        // plain attribute value from the model.
        if ($inPaths) {
            return $this->getPathValue($key);
        }
    }
697000
protected function castAttribute($key, $value)
	{
		if (is_null($value)) return $value;

		switch ($this->getCastType($key))
		{
			case 'int':
			case 'integer':
				return (int) $value;
			case 'real':
			case 'float':
			case 'double':
				return (float) $value;
			case 'string':
				return (string) $value;
			case 'bool':
			case 'boolean':
				return (bool) $value;
			case 'object':
				return json_decode($value);
			case 'array':
			case 'json':
				return json_decode($value, true);
			case 'collection':
				return $this->newCollection(json_decode($value, true));
			default:
				return $value;
		}
	}
40062
protected function attribute($key, $value)
    {
        if (is_numeric($key)) {
            $key = $value;
        }

        if (!is_null($value)) {
            return $key.'="'.$value.'"';
        }
    }
278048
protected function mutableMutate($key, $value, $dir)
    {
        $mutators = $this->getMutatorsForAttribute($key, $dir);

        return static::$attributeMutator->mutate($value, $mutators);
    }
544855
public function setAttribute($key, $value)
    {
        if (array_key_exists($key, static::$attributeTypeMapping)) {
            $type = strtolower(static::$attributeTypeMapping[$key]);
            switch ($type) {
                case 'boolean':
                case 'bool':
                    $value = (bool) filter_var($value, FILTER_VALIDATE_BOOLEAN);
                    break;
                case 'integer':
                case 'int':
                    $value = (int) $value;
                    break;
                case 'float':
                    $value = (float) $value;
                    break;
                case 'string':
                default:
                    $value = (string) $value;
                    break;
            }

            $this->attributes[$key] = $value;
        } else {
            throw new \InvalidArgumentException("Unexpected attribute '$key'.");
        }

        return $this;
    }
1368217
public function setAttribute($key, $value = null)
    {
        if (is_array($key) && is_null($value)) {
            $this->attributes = $key;
        } else {
            array_set($this->attributes, $key, $value);
        }

        return $this;
    }
50238
protected function setAttribute($key, $value)
    {
        if (is_null($value)) {
            $this->attributes[$key] = null;

            return $this;
        }

        if (in_array($this->getKeyType($key), ['json', 'datetime', 'tags'])) {
            $this->attributes[$key] = $this->cast($this->getKeyType($key), $value);

            return $this;
        }

        if ($this->getKeyType($key) === 'relation') {
            $this->attributes[$key] = new self((array) $value);

            return $this;
        }

        if ($this->getKeyType($key) === 'media') {
            $this->attributes[$key] = new AssetFile((array) $value);

            return $this;
        }

        if ($this->getKeyType($key) === 'relation') {
            $this->attributes[$key] = new self((array) $value);

            return $this;
        }

        $this->attributes[$key] = $value;

        return $this;
    }