Answers for "how to get sum of columns group by some column in laravel eloquent"

PHP
2

laravel sum group by

$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
Posted by: Guest on April-05-2021

Code answers related to "how to get sum of columns group by some column in laravel eloquent"

Browse Popular Code Answers by Language