我有一个数据库表Wys_teachers
,其中包含以下表格字段
我正在插入以下值:
1,15,07,2015,1 1 2,15,07,2015,1 1 3,15,07,2015,1 1 4,15,07,2015,0,去医院 5,15,07,2015,1
然后我想更新id=4
,以便t_attendance
一次变为1,加上t_areason
字段为空(删除go to hospital
)。
我的控制器更新代码是:
`if(!$teachers->isEmpty()) {
foreach ($teachers as $teacher) {
$updatet_attendance = WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->update(array(
't_attendance'=>Input::get($teacher->user_id),
));
$allattendance= WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->get();
$reason=$allattendance->t_areason;
if(!$allattendance->isEmpty()) {
DB::table('wys_teacherattendances')
->where('t_auserid',$teacher->user_id)
->where('t_adate','=',$date_exploded[0])
->where('t_amonth','=',$date_exploded[1])
->where('t_ayear','=',$date_exploded[2])
->where('t_aresaon','!=',NULL)
->delete();
}
}
//return Redirect::route('GetTeachersearchAttendence')
// ->with('success','update teacher exist');
}
}`
更新条件没问题 - t_attendance = 0
- 值变为t_attendance = 1
。但t_areason
未被删除。
此部分代码无效:
`$allattendance= WysTeacherattendance::where('t_auserid',$teacher->user_id)
->where('t_adate', $date_exploded[0])
->where('t_amonth', $date_exploded[1])
->where('t_ayear', $date_exploded[2])
->get();
$reason=$allattendance->t_areason;
if(!$allattendance->isEmpty()) {
DB::table('wys_teacherattendances')
->where('t_auserid',$teacher->user_id)
->where('t_adate','=',$date_exploded[0])
->where('t_amonth','=',$date_exploded[1])
->where('t_ayear','=',$date_exploded[2])
->where('t_aresaon','!=',NULL)
->delete();
}`
我不知道这是对还是错。
如何解决这个问题? 以及如何检查某个特定字段是否为空?