我只需要及时更新多行。
一次可以插入多行,如下面的代码,
foreach ($request->something as $key => $value) {
$data=array(
'db_table_field0'=> $request->form_something[$key],
'db_table_field1'=>$request->form_something2[$key],
'db_table_field2'=>$request->form_something3[$key],
'db_table_field3'=>$request->form_something4[$key],
);
tableModel::insert($data);
}
数据正在插入,我尝试了同样的更新,如
foreach ($request->something as $key => $value) {
$auc_det_id = tableModel::where('value', $request->value[$key])->get();
$data=array(
'db_table_field0'=> $request->form_something[$key],
'db_table_field1'=>$request->form_something2[$key],
'db_table_field2'=>$request->form_something3[$key],
'db_table_field3'=>$request->form_something4[$key],
);
$auc_det_id->update($data);
}
它没有更新,没有找到类似方法更新的错误。我还尝试了save()
而不是update()
。
我检查了null $auc_det_id
是否数据未保存(无错误)
答案 0 :(得分:2)
您可以尝试:
$data=array(
'db_table_field0'=> $request->form_something[$key],
'db_table_field1'=>$request->form_something2[$key],
'db_table_field2'=>$request->form_something3[$key],
'db_table_field3'=>$request->form_something4[$key],
);
tableModel::where('value', $request->value[$key])->update($data);