I am querying a large data sets from the table and then iterating through a loop for creating a json file.
$user = App\User::all();
foreach($user as $val){
// logic goes here for creating the json file
}
Now the problem i am facing is that when iterating through the loop it is consuming memory and i am getting error 'Allowed memory size exhausted'.And also the cpu usage of the server becomng so high. My question how i should use the laravel lazy collections to get rid of this issue.I have gone through the offcial docs but couldnt find the way.
foreach
loop? and you can't find the way to do what? – Brashearfilter
call (as that is just an example) "However, the query builder'scursor
method returns a LazyCollection instance." – Brashearcursor
method then it iterates it with aforeach
loop – Brashear