Skip to content
Advertisement

My Laravel Code running slow because foreach, should i change my query to chunk? and how to optimize it?

The concept is simple that i want to sum some value that name total_hs from table analysis with same workingname. This code running so slow because of foreach if has alot of data.

JavaScript

and for model like this

JavaScript

Advertisement

Answer

You want to return total value for every workingname, If I understand. You can replace your function with the new one that I mention below.so, It’s might be helpful:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement