我想要的是拥有超过缺席次数的if语句并显示消息。
这是SQL查询
public function countAbsent()
{
$absent = Attendances::select(DB::raw('count(status)'))
->where('student_id', '=', Auth::user()->id)
->where('status', '=', 'absent')
->where('section_name', 'like', Input::get('section_name'))
->where('subject_code', 'like', Input::get('subject_code'))
->count();
return View::make('student.view_absent')
->with('absent', $absent);
}
答案 0 :(得分:1)
您可以传递另一个变量来查看:
public function countAbsent()
{
$absent = Attendances::select(DB::raw('count(status)'))
->where('student_id', '=', Auth::user()->id)
->where('status', '=', 'absent')
->where('section_name', 'like', Input::get('section_name'))
->where('subject_code', 'like', Input::get('subject_code'))
->count();
$absent_message = 'Students are not exceeding the absence threshold';
$threshold = 10; //whatever you like
if ($absent > $threshold)
{
$absent_message = 'Students are exceeding the absence threshold';
}
return View::make('student.view_absent')
->with('absent', $absent)
->with('absent_message', $absent_message);
}
并在视图$absent_message
中回显student.view_absent
。