0x00 0x00 - 4 months ago 14
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();
if($row)
{
$row->field_value = "new value";
$row->save();
}


Suddenly all rows
field_value
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.

Answer

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.