Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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
Comment

sum of each group in laravel

$sums = $detailed->mapWithKeys(function ($group, $key) {
    return [$key => $group->sum('sales_price')];
});
Comment

find sum of each group in laravel

$sums = $detailed->mapWithKeys (function ($group, $key) { return [$key => $group->sum ('sales_price')]; });
Comment

PREVIOUS NEXT
Code Example
Php :: Bootstrap paginator css not appearing 
Php :: update php local 
Php :: laravel how to check app env 
Php :: php ternary string 
Php :: php multi string to single string 
Php :: jsondecode 
Php :: how to add custom navigation menus in wordpress themes 
Php :: laravel id generator 
Php :: php unix socket client 
Php :: run queue after x minutes laravel 
Php :: laravel update method 
Php :: set border phpoffice phpexcel 
Php :: difference between array_merge and + 
Php :: php get highest value in multidimensional array 
Php :: generate a unique id 
Php :: pagination using ajax 
Php :: laravel telescope tutorial 
Php :: php fetch return false 
Php :: laravel set timezone dynamically 
Php :: how to update a table based on three columns laravel 
Php :: php replace url parameter value 
Php :: add column migration laravel 8 
Php :: laravel echo 
Php :: sweet alert confirm box laravel 
Php :: middleware in laravel 
Php :: laravel route namespace 
Php :: whats the difference between using date function and DATETime in php 
Php :: how to update dropdown value in laravel 
Php :: create xml php 
Php :: php array_slice 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =