Eloquent update json column with dot key #50313
Unanswered
AntistressStore
asked this question in
Q&A
Replies: 0 comments
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.
-
I can't find any information on how to properly update json values with dots in the key. Can you tell me where to clarify this information and how to do it? Is it possible to do this by means Eloquent? ->update method Or only through a raw query?
in db column
state
, we have this data{"2.7":35,"2.9":24,"2.95":8.99}
I have all tried. With or without shielding. Values with dots are saved successfully. Keys with dots cannot be obtained and updated. don't work
The operation is successful, but there is no result. The value does not change.
Having studied the operations that Eloquent. I've discovered several methods that split the key using a dot. There is also a method that checks whether this key is populated. Illuminate\Database\Eloquent\Concerns\GuardsAttributes::isFillable
It is he who is responsible for the fact that a value with a key with a dot cannot be written down. It defines it as not writable.
If you experimentally comment out the last lines
! str_contains($key, '.')
, the result will be recorded. But it is broken into separate keys. 2.7 becomes a nested array with keys 2 and 7.Beta Was this translation helpful? Give feedback.
All reactions