0x00 0x00 - 3 months ago 5
PHP Question

Lumen with Eloquent arbitrary changes all fields

Here's the code:

$row = UserFields::where(['user_id' => $user['user_id'], 'field_id' => 'myfield'])->first();
$row->field_value = "new value";

Suddenly all rows
in that table changes to the new value and only for that user!

That's really confusing, I don't know if it's a bug in Eloquent.


For anyone having the same issue I managed to solve this by using basic lumen db query method:

app('db')->update("UPDATE `xf_user_field_value` SET `field_value` = ? WHERE (user_id = ? AND field_id = ?);", [ $newValue, $user_id, $column ]);

I have completely disabled Eloquent as it was overkill for me and not flexible enough for my needs.