Skip to content

Commit

Permalink
Extract setting mutated attribute into method
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed May 24, 2018
1 parent 07b4bf7 commit 5837438
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 5837438

Please sign in to comment.