Home >PHP Framework >Laravel >Avoid the trap! Laravel update data pitfalls
The following is the Laravel framework tutorial column to share with you the pitfalls of Laravel update data, I hope it will be helpful to friends in need!
Usually we have the following methods to update data:
$model = Model::find($id);$model->field1 = $value1;$model->field2 = $value2;$model->save();
Model::find($id) ->update([ 'field1' => $value1, 'field2' => $value2, ]);
Model::query() ->where('id', $id) ->update([ 'field1' => $value1, 'field2' => $value2, ]);
All three methods can update data. If it were you, which method would you choose? Or which method has the best performance?
The above is the detailed content of Avoid the trap! Laravel update data pitfalls. For more information, please follow other related articles on the PHP Chinese website!