Requirement about Eloquent Acessor json serialization #50432
Unanswered
EronAlves1996
asked this question in
Q&A
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Given a model with a
price
field, that maps directly to a databaseprice
field, I am creating an Eloquent mutator/acessor for it, like this:But I found that, when I configure this attribute to append it to json serialization like this:
It fails with a exception:
Investigating the reason behind this, finally I found that overriding existing fields of Model with acessor/mutator requires enabling the attributes caching like this:
This should be on the docs, it isn't? In this page, that talks especifically about acessors/mutators on eloquent, and this page that talks about eloquent serialization, I dont found any information about pitfalls in appending existing fields acessors to json.
Beta Was this translation helpful? Give feedback.
All reactions