Skip to content

Commit 9513af1

Browse files
committed
Override setAttributeMarkedMutatedAttributeValue method;
1 parent 849cb1f commit 9513af1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Eloquent/Model.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,37 @@ public function attributesToArray()
251251
return $attributes;
252252
}
253253

254+
/** @inheritdoc */
255+
protected function setAttributeMarkedMutatedAttributeValue($key, $value)
256+
{
257+
$attribute = $this->{Str::camel($key)}();
258+
259+
$callback = $attribute->set ?: function ($value) use ($key) {
260+
$this->attributes[$key] = $value;
261+
};
262+
263+
$normalizeCastClassResponse = $this->normalizeCastClassResponse(
264+
$key, $callback($value, $this->attributes)
265+
);
266+
267+
if (count($normalizeCastClassResponse) > 1) {
268+
$normalizeCastClassResponse = [$key => $normalizeCastClassResponse];
269+
}
270+
271+
$this->attributes = array_merge(
272+
$this->attributes,
273+
$normalizeCastClassResponse
274+
);
275+
276+
if ($attribute->withCaching || (is_object($value) && $attribute->withObjectCaching)) {
277+
$this->attributeCastCache[$key] = $value;
278+
} else {
279+
unset($this->attributeCastCache[$key]);
280+
}
281+
282+
return $this;
283+
}
284+
254285
/** @inheritdoc */
255286
public function getCasts()
256287
{

0 commit comments

Comments
 (0)