2015-04-18 44 views
0

我只需要一个超过缺勤数量并显示消息的if语句。带警告消息的Laravel DB查询

这里的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

那么警告信息是什么? – Killrawr

回答

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); 


} 

和回声在查看student.view_absent$absent_message