Packy Packy - 1 year ago 89
PHP Question

php array combine values - laravel

I have an data model for sales that looks like:

| id | dist_abbv | invoice | account | brand | quantity

Now when I dump out an account sales I will get an array (actually a laravel collection) like:


"id" => 2113
"dist_abbv" => "CARDMT"
"date" => "2016-06-23"
"invoice" => 597935
"brand" => "ID46C"
"quantity" => 1
"account_vip_id" => 10010

How can I loop through this and combine all the same
and total up the quantity? So opposed to 10 entries with only 2 different brands I get 2 entries with each brands total sales?

Answer Source

Try to use :

   ->select('brand', 'sum(quantity) as total')

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download