location_id] = ($totalsByLocation[$row->location_id] ?? 0) + $row->quantity; } foreach ($locations as $location) { $location->totalQuantity = $totalsByLocation[$location->id] ?? 0; $location->route = $router->route('view-location', ['location' => $location->id]); } return view('locations/index', [ 'locations' => $locations, 'createAction' => $router->route('show-create-location-form'), 'canManage' => session()->has('user_id'), ]); } }