用selectRaw查看laravel视图

时间:2018-06-19 08:11:06

标签: php laravel

我想显示des = test1的分数总和;

    $data=" ";
    $student = Student::find(1)->student;
    $scores = Score::where('school_id',$request->id)
    ->selectRaw('sum(score) as test, where des = Test1')
    ->groupBy('student_id','des')
    ->get();
    if($scores)
    {
      $i=1;
      foreach ($scores as $score)
      {
        $data .= '<tr><td>'.$i++.'</td>
                <td>'.$score->student['name'].'</td>
                <td>'.$score->test.'</td>
                </tr>';
      }
      return Response($data);
    }

1 个答案:

答案 0 :(得分:0)

where子句不属于selectRaw语句。使用字符串时where子句也应保留在where des ='test1'

之类的引号内