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 :)
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community