[英]Can't update collection in Laravel eloquent
There is a table with the following structure: (primary keys: user_id, record_id)有一个表结构如下:(主键:user_id,record_id)
+---------+-----------+-------+ | user_id | record_id | value | +---------+-----------+-------+ | 1 | 1 | 100 | | 1 | 2 | 200 | | 2 | 1 | 300 | | 2 | 2 | 400 | +---------+-----------+-------+
When i change value parameter over eloquent-query in my Controller like this:当我在 Controller 中通过 eloquent-query 更改值参数时,如下所示:
$playerRecord = Test::where('user_id', '=', $player_id)->where('record_id', '=', '1')->first();
$playerRecord->value = $user_value1;
$playerRecord->save();
I have an error: https://flareapp.io/share/47qg8ZEm#F49我有一个错误: https://flareapp.io/share/47qg8ZEm#F49
If I define only one primary key in the model, all records with this key are updated, despite the fact that I forced to update a specific record.如果我在 model 中仅定义一个主键,则所有具有此键的记录都会更新,尽管我强制更新特定记录。
$playerRecord = Test::where('user_id', '=', $player_id)->where('record_id', '=', '1')->update(['value'=>$user_value1]);
if($playerRecord){
return "data updated";
}else{
return "data not found";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.