如果还没有满足以下条件的行,我将尝试创建一个新行:['employee_id' => $id, 'competence_id' => $getCompetenceKey]或者如果它已经存在,我更新它并设置 >所以我这么做了:foreach($request->input('competence') as $getCompetenceKey => $getCompetenceValue) { EmployeeCompetence::updateOrCreate( ['employee_id' => $id,'competence_id' => $getCompetenceKey], ['value' => $getCompetenceValue] );}但它似乎不能正常工作:https://i.imgur.com/CNPZ2AB.png但我可以这样做:foreach ($request->input('competence') as $getCompetenceKey => $getCompetenceValue) { $e = EmployeeCompetence::where('employee_id', $id)->where('competence_id', $getCompetenceKey); if ($e->count() > 0) { $e->update(['value' => $getCompetenceValue]); } else { EmployeeCompetence::create(['employee_id' => $id, 'competence_id' => $getCompetenceKey, 'value' => $getCompetenceValue]); }}但我真的想知道为什么updateOrCreate()函数对我不起作用。谢谢,肯尼 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 第一列用于update,但它也应该在create函数中传递。例子:EmployeeCompetence::updateOrCreate( [ 'employee_id' => $id, 'competence_id' => $getCompetenceKey ], [ 'value' => $getCompetenceValue, 'employee_id' => $id, 'competence_id' => $getCompetenceKey ]); (adsbygoogle = window.adsbygoogle || []).push({}); 10-06 15:59