1

i need to do this operation:

introducir la descripción de la imagen aquí

Count the total of each number of records with a different 'rrpp': 1,2,3,4 ∞

I always use this to sum the records of a RRPP:

  $variable = Modelo::where('dia_id' , $request->id)->where('rrpp' , 1)->count('id');

but this way I only get the result of 1 in specific. And what I need is to get the result like this

help, thanks

seonica
  • 51
  • 6
  • 2
    Does this help https://stackoverflow.com/questions/18533080/laravel-eloquent-groupby-and-also-return-count-of-each-group – Jacob Mulquin Apr 18 '22 at 02:39

1 Answers1

0

you only get result 1 because you use this where('dia_id' , $request->id) in your query, if you want to count rrpp=1 use this query:

$variable = Modelo::where('rrpp' , 1)->count('id');

if you want to count all rrpp use this query:

$variable = Modelo::select('rrpp', 
    DB::raw('count(*) as total'))
    ->groupBy('rrpp')
    ->get()