Skip to content

Commit 894fe22

Browse files
committed
dont cache non objects
1 parent 0acc405 commit 894fe22

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,17 @@ protected function getClassCastableAttributeValue($key, $value)
560560
} else {
561561
$caster = $this->resolveCasterClass($key);
562562

563-
return $this->classCastCache[$key] = $caster instanceof CastsInboundAttributes
564-
? $value
565-
: $caster->get($this, $key, $value, $this->attributes);
563+
$value = $caster instanceof CastsInboundAttributes
564+
? $value
565+
: $caster->get($this, $key, $value, $this->attributes);
566+
567+
if ($caster instanceof CastsInboundAttributes || ! is_object($value)) {
568+
unset($this->classCastCache[$key]);
569+
} else {
570+
$this->classCastCache[$key] = $value;
571+
}
572+
573+
return $value;
566574
}
567575
}
568576

0 commit comments

Comments
 (0)