Я хочу вставить или обновить строки в таблицу моделей. Но не могу понять запрос.
SmStudentAttendance Это моя модель.
$students — моя коллекция.
Я поместил поля коллекции в массивы.< /p>
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');
}
Теперь я хочу вставить их, если строка для Student_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
Подробнее здесь: https://stackoverflow.com/questions/663 ... to-a-tablr