我想要的只是有一个超过缺席次数的 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);
}
最佳答案
您可以传递另一个变量来查看:
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);
}
并在 View student.view_absent
中回显 $absent_message
。
关于php - 带警告消息的 Laravel DB 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29711850/