Home > PHP Framework > Laravel > body text

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

藏色散人
Release: 2020-11-17 15:01:42
forward
1949 people have browsed it

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();
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!