JSON/Array data throws error on insert, but ok on Update #40061
Unanswered
kieranmetcalfe
asked this question in
General
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 have a situation where I'm gathering data in a Form using field[key] notation. This creates an array when received on the controller.
I then use
When this is an update to an existing model, this saves correctly, with the incoming array converted to JSON. However, an insert / new model fails with Array to String conversion.
It looks like the issue is that Illuminate\Database\Query\Builder::update function calls:
$this->grammar->prepareBindingsForUpdateFrom($this->bindings, $values)
which includes a call to json_encode any arrays, but the insert process via insertGetId() doesn't have any such conversion in the flow, so the value is still an array when it comes to binding the query.Is there a reason why the Insert side doesn't do these checks? It feels like it should be doing if the update side has it?
Beta Was this translation helpful? Give feedback.
All reactions