The method I wrote does not work with model, thank you for your feedback! I fixed the article using cursor which is simpler!
foreach(User::cursor()as$user){yield$user;}
Still you could chunk by larger slices manually, like in this code:
// Generator functionfunctiongetUsersOneByOne(){// build your chunks as you want (200 chunks of 10 in this example)for($i=0;$i<200;$i++){$users=DB::table('users')->skip($i*10)->take(10)->get();// Yield user one by oneforeach($usersas$user){yield$user;}}}// Export consumes only a few MB(newFastExcel(getUsersOneByOne()))->export('test.xlsx');
Thank you!!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Showing Error: Can use "yield from" only with arrays and Traversables. Can you help?
The method I wrote does not work with model, thank you for your feedback! I fixed the article using
cursor
which is simpler!Still you could chunk by larger slices manually, like in this code:
Thank you!!