diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 3ae53bc38f7b..d3fd76e8b418 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -543,9 +543,7 @@ public function setAttribute($key, $value) // which simply lets the developers tweak the attribute as it is set on // the model, such as "json_encoding" an listing of data for storage. if ($this->hasSetMutator($key)) { - $method = 'set'.Str::studly($key).'Attribute'; - - return $this->{$method}($value); + return $this->setMutatedAttributeValue($key, $value); } // If an attribute is listed as a "date", we'll convert it from a DateTime @@ -582,6 +580,18 @@ public function hasSetMutator($key) return method_exists($this, 'set'.Str::studly($key).'Attribute'); } + /** + * Set the value of an attribute using its mutator. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + protected function setMutatedAttributeValue($key, $value) + { + return $this->{'set'.Str::studly($key).'Attribute'}($value); + } + /** * Determine if the given attribute is a date or date castable. *