首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel DB query with warning message

Laravel DB query with warning message
EN

Stack Overflow用户
提问于 2015-04-18 09:25:58
回答 1查看 166关注 0票数 0

所有我想要的是有一个超过缺席次数的if语句,并显示消息。

下面是SQL查询

代码语言:javascript
复制
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);


    }
EN

回答 1

Stack Overflow用户

发布于 2015-04-18 16:54:05

您可以传递另一个变量来查看:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29711850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档