【发布时间】:2021-05-28 18:06:04
【问题描述】:
我想在我的模型表中插入或更新行。但无法弄清楚查询。 SmStudentAttendance 这是我的模型。 $students 是我的收藏。
我已将集合字段放入数组中。
foreach ($students as $student) {
array_push($temp_id, $student->id);
array_push($temp_lastname, $student->last_name);
array_push($temp_academic_id, $student->academic_id);
array_push($temp_attendance, 'P');
array_push($temp_attendancedate, $date);
array_push($temp_schoolid, '1');
array_push($temp_updatedby, '1');
array_push($temp_createdby, '1');
}
现在我想插入它们,如果表中不存在学生 ID 和出勤日期的行,否则如果它已经存在则更新。 这是查询:
SmStudentAttendance::upsert('attendance_type', $temp_attendance, 'attendance_date', $temp_attendancedate, 'student_id', $temp_id, 'created_by', $temp_createdby, 'updated_by', $temp_updatedby, 'school_id', $temp_schoolid, 'academic_id', $temp_academic_id);
我得到的错误:
Argument 1 passed to Illuminate\Database\Eloquent\Builder::upsert() must be of the type array, string given, called in D:\xampp\htdocs\sms\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php on line 23
【问题讨论】:
标签: mysql database laravel collections