“Laravel Sum Group por” Respostas de código

Laravel Sum Group por

$docs = Document::groupBy('users_editor_id')
   ->selectRaw('sum(no_of_pages) as sum, users_editor_id')
   ->get(); //this return collection 

//In Blade
@foreach($docs as $doc)
	{{$doc->users_editor_id}} >-------< {{$doc->sum}}
@endforeach
Witty Wasp

SQL Select Sum Group by Id Laravel

Document::groupBy('users_editor_id')
   ->selectRaw('sum(no_of_pages) as sum, users_editor_id')
   ->pluck('sum','users_editor_id');

   // originally lists(), which was deprecated in favour of pluck in 5.2
   // and dropped completely in 5.3
   // ->lists('sum','users_editor_id');


// returns array like this:
array(
  users_editor_id => sum,
  ...
)
Clear Cat

Respostas semelhantes a “Laravel Sum Group por”

Perguntas semelhantes a “Laravel Sum Group por”

Mais respostas relacionadas para “Laravel Sum Group por” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código