Closed
Closed
Copy link
Description
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):
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 works as intended:
$p= Post::first();
dd($p->id);
This calls the set for title:
$p= Post::first();
$p->title;
dd($p->id);
Metadata
Metadata
Assignees
Labels
No labels