大家好我需要帮助将多个复选框保存到数据库中。我试过这样做,但它似乎没有用。我不太确定如何正确使用它,但这是我如何做到的,有人可以纠正我如何正确地做到这一点?提前谢谢。
这是我的代码:(目前收到此错误:Array to string conversion
在其他地方指向此部分,$id->evaluations()->save($Evaluation);
)
if(count($request->input('Pending_Remarks1')|| $request->input('Pending_Remarks2') || $request->input('Pending_Remarks3')) >1){
$Evaluation['Pending_Remarks1'] = implode(' , ', $request->Pending_Remarks1);
$Evaluation['Pending_Remarks2'] = implode(' , ', $request->Pending_Remarks2);
$Evaluation['Pending_Remarks3'] = implode(' , ', $request->Pending_Remarks3);
$id = $request->user_id;
$id= PersonalInfo::find($id);
$id->evaluations()->save($Evaluation);
}else{
$Evaluation->Pending_Remarks1 = $request->input('Pending_Remarks1');
$Evaluation->Pending_Remarks2 = $request->input('Pending_Remarks2');
$Evaluation->Pending_Remarks3 = $request->input('Pending_Remarks3');
$id = $request->user_id;
$id= PersonalInfo::find($id);
$id->evaluations()->save($Evaluation);
}
在过去,我做过类似的事情并且有效,但是当我尝试为待处理的备注代码执行此操作时,它无法正常工作。
if(count($request->input('Driver_license_class'))>1){
$testa['Driver_license_class'] = implode(' , ', $request->Driver_license_class);
$object->update($testa);
}else{
$object->Driver_license_class = $request->input('Driver_license_class');
$object->update();
}
答案 0 :(得分:0)
假设你得到的错误是第一个$id->evaluations()->save($Evaluation);)
,我相信你需要设置该对象的属性而不是设置数组。看起来Laravel无法保存数据,因为它是一个标准数组。
if(count($request->input('Pending_Remarks1')|| $request->input('Pending_Remarks2') || $request->input('Pending_Remarks3')) >1){
$Evaluation->Pending_Remarks1 = implode(' , ', $request->Pending_Remarks1);
$Evaluation->Pending_Remarks2 = implode(' , ', $request->Pending_Remarks2);
$Evaluation->Pending_Remarks3 = implode(' , ', $request->Pending_Remarks3);
}else{
$Evaluation->Pending_Remarks1 = $request->input('Pending_Remarks1');
$Evaluation->Pending_Remarks2 = $request->input('Pending_Remarks2');
$Evaluation->Pending_Remarks3 = $request->input('Pending_Remarks3');
}
if(isset($request->user_id)){
$id = $request->user_id;
$id= PersonalInfo::find($id);
$id->evaluations()->save($Evaluation);
}