Support the ongoing development of Laravel.io →
Laravel Eloquent
Last updated by @liquid207 9 months ago.
0
moderator

Hello @liquid207

Is the code you provider your whole class or only a part?

You can do a dump in your mutator but I suspect you have another value for name then you think.

    public function getNameAttribute($value)
    {
        dump($value);
        return strtoupper($value);
    }

And strtoupper will make everything uppercase, so the expected result will be:

[
    "id" => 1,
    "name" => "FOO",
]

Sidenote: the mutators are rewritten to a new way, see: https://laravel.com/docs/10.x/eloquent-mutators

The old version is currently still working so it shouldn't be a problem but If you need to change it I mostly suggest to update it :)

0

@tvbeek

Thanks, you are right, I have updated description.

My key point is:

Incorrect accessor value ('' in this example) in Model::toArray() when a Model contains an accessor (getNameAttribute in this example) with the same name as a column and accessor name is added to Model::$appends

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Crosshadow liquid207 Joined 13 Mar 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.