Error when using whereRaw in Laravel

1

What am I doing wrong in this queryRaw ? The goal is to display the sum values if ID = ID, but I'm getting the total sum of the column.

Excerpt from the Controller query:

//Show
public function show( Pesquisa $pesquisa )
{
    $this->guardaAvaliacao( $pesquisa );

    $pesquisa->load( [
        'respostas' => function ( $relation ) {
            $relation->with( [ 'pergunta.opcoes', 'opcao' ] );
        }
    ] );

    $nota = DB::table('clima.tbl_resposta_super')
        ->selectRaw('sum(nota_original) as nota_original ')
        ->whereRaw('tbl_resposta_super.pesquisa_id', '=' .$pesquisa->id)
        ->groupBy('nota_original')
        ->get();


    dd($nota);

}
    
asked by anonymous 27.08.2018 / 23:00

2 answers

1

When using whereRaw you do not need to separate the operator as an argument, like where .

$nota = DB::table('clima.tbl_resposta_super')
        ->selectRaw('sum(nota_original) as nota_original ')
        ->whereRaw('tbl_resposta_super.pesquisa_id = ' .$pesquisa->id)
        ->groupBy('nota_original')
        ->get();
    
28.08.2018 / 00:18
0

For those who have the same doubt, resolution follows.

        //Recupera e soma Notas
    $notas = DB::table('clima.tbl_resposta_super')
        ->select(DB::raw('sum(nota_original) as nota_original,sum(nota_supervisor) as nota_supervisor, pesquisa_id'))
        ->where('tbl_resposta_super.pesquisa_id', '=', $pesquisa->id)
        ->groupBy('pesquisa_id')
        ->get();
    
29.08.2018 / 16:15