4 months ago

Sum of model attributes with same ID

Posted 4 months ago by Bom_Basti

I want to calculate the sum of the volume flows (attribute) of different ventilation units (model) previously selected by the user.

However, I cannot use System->whereIn('id', $selectedSystemIDs)->sum('volume_flow') because the user can also select the same units for different rooms. The array of IDs could look like this:

array:3 [▼
  0 => 9
  1 => 10
  2 => 10

Is there a Laravel way to do this or do I have to solve it with a loop?

Please sign in or create an account to participate in this conversation.