Want to ask earlier, I did insert add data in the attendance_details table, it worked, but I want the attendance table to be automatically changed to the Done table to 1 before 0 before submitting. But the error at signup says something like this Method IlluminateDatabaseEloquentCollection::save does not exist. Here is my MySQL table:
Table attendance_details:
Screenshot Table attendance_details in MySQL
and table attendance:
Screenshot Table attendance
in the attendance table there is a Done table still 0 after submitting it should be changed to 1
Code:
Blade
<form method="POST" action="{{route('add.data')}}" enctype="multipart/form-data">
@csrf
<input type="hidden" name="id_atte" value="{{ $dataAttendance->id_atte }}"
>
Controller
public function AddData(Request $request) {
// Add Data attendance_details
foreach($request->get('id_atte') as $index => $value) {
AttendanceDetail::create([
'id_atte' => $value,
'id_student' => $request->get('id_student')[$index],
'id_atte_type' =>$request->get('id_atte_type')[$index],
'note' => $request->get('note')[$index]
]);
}
// Update Data attendance
$data = Attendance::find($request->id_atte);
$data->done = '0';
$data->save();
return redirect('teacher/data-attendance');
}
Where is the coding wrong?