Home  >  Article  >  PHP Framework  >  How to solve the problem that Laravel's modified data is the same as the original data, resulting in no SQL execution

How to solve the problem that Laravel's modified data is the same as the original data, resulting in no SQL execution

藏色散人
藏色散人forward
2020-11-17 15:01:421952browse

The following column Laravel Tutorial will introduce to you LaravelThe solution to modify the data to be the same as the original data, resulting in no sql execution, I hope it will be helpful to you Friends in need help!

How to solve the problem that Laravel's modified data is the same as the original data, resulting in no SQL execution

Code

$openid = "123"; // 微信openid
User::WhereIn("id",['1','2','3'])->update([
  'openid' => $openid
]);

$user = User::find(1);

// 取消所有这个openid的绑定者
User::Where(['openid' => $openid])->update([
  'openid' => null
]);

// 给1号用户绑定openid
$user->openid = $openid;
$user->save();

Question: openid = 123 How many are there?
Answer: One nothing.

Reason

How to solve the problem that Laravels modified data is the same as the original data, resulting in no SQL execution

##getDirty will return the original of $user (queried ones are not allowed to change) and attributes (manually assigned values) are different.

Finally found that the attributes are the same, so

$user->save () No modification will be performed.

##BullshitWhen I was writing

WeChat binding

, I noticed something was wrong. I thought it was laravel or mysqlbug                                              

The above is the detailed content of How to solve the problem that Laravel's modified data is the same as the original data, resulting in no SQL execution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete