Here the scenario is, I have 3 models/tables:
1. Teacher
2. Course
3. Course Assign to Teacher
In the Teacher
model/table there are two columns named: credit_taken
and remaining_credit
(default 0
) and in the Course
model/table there is a course_credit
column.
So here is the problem: in the model/table Course Assign to Teacher
when a Teacher
takes a Course
the value of this column should be calculated like this:
remaining_credit = credit_taken - course_credit
I have implemented this, however instead of the value updating in database it's creating a new row in the Teachers
table.
Here is my controller:
public function postcourseAssignTeacher(Request $request)
{
$assignTeacher = new AssignTeacher();
$assignTeacher->teacher_id = $request->Input(['teacher_id']);
$teacher->credit_taken = $request->Input(['credit_taken']);
$teacher->remaining_credit = $request->Input('remaining_credit');
$assignTeacher->course_id = $request->input('course_id');
$course->name = $request->Input('name');
$course->credit = $request->Input('credit');
$teacher->remaining_credit = $teacher->credit_taken -$course->credit;
$assignTeacher->save();
// $course->save();
$teacher->update();
return redirect('courseAssignTeacherPage');
}
How do I update above two columns in teacher table instead of inserting a new record.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…