Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

A get on attributes calls the set for attributes listed in attribute cast cache #55596

Copy link
Copy link
Closed
@rikvdh

Description

@rikvdh
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.