You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__get from an eloquent model runs through mergeAttributesFromAttributeCasts, which calls the set (when present) on every model part of the attributeCastCache.
When I have an set for a model which returns an object, it is the default behavior to cache that. Also for other cached attributes, the set is called for every get (even when the retrieved attribute is unrelated).
Steps To Reproduce
When you make a model (e.g. Post) with an attribute in it (proof-of-concept, you can imagine object serialization and unserialization here):
protected function title(): Attribute
{
return Attribute::make(
get: function ($attrData) {
return new stdClass;
},
set: function () {
throw new \Exception('the set should never be called!');
}
);
}
This discussion was converted from issue #55596 on May 19, 2025 06:58.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Laravel Version
11.x, 12.x
PHP Version
8.3
Database Driver & Version
n/a
Description
__get from an eloquent model runs through
mergeAttributesFromAttributeCasts
, which calls the set (when present) on every model part of the attributeCastCache.When I have an set for a model which returns an object, it is the default behavior to cache that. Also for other cached attributes, the set is called for every get (even when the retrieved attribute is unrelated).
Steps To Reproduce
When you make a model (e.g. Post) with an attribute in it (proof-of-concept, you can imagine object serialization and unserialization here):
This works as intended:
This calls the set for title:
Beta Was this translation helpful? Give feedback.
All reactions