我有一些代码
public function addvote($id,$varia){
$pollsres = Pollsres::where('poll_id', '=',$id)->where('poll_variant','=',$varia)->get();
// and poll_variant = ?',[$id,$varia])->get();
if($pollsres->isEmpty()){
$pollres = new Pollsres();
$pollres->poll_id = $id;
$pollres->poll_variant = $varia;
$pollres->poll_count = 1;
$pollres->save();
}else{
//return response()->json($pollsres);
var_dump($pollsres);
}
}
在db中我有1条记录$ id = 1和$ varia = 1但是我可以更新$ pollsres-> poll_count我有错误,如果我更新$ pollsres [0] - > poll_count我更新所有记录没有只有为什么有表达式(在db中测试whith 2记录)
我要检查我是否在数据库中有记录,如果没有添加新的话,如果有编辑此记录
答案 0 :(得分:1)
因为您的表没有primary key
。
您需要为您的表添加auto increment
主键,因为Laravel/Lumen does not support composite primary key (i.e: 2 primary keys or more)。
然后问题就会解决。