PHP generators can be confusing to understand. Why and when would I reach for them? The easiest answer to this question is when you're working with very large datasets. A generator allows us to circumvent memory limit concerns by iterating over data without first building up a large array in memory.
As of Laravel 6, generators are now used when lazy-loading collections.
Published on Sep 2nd, 2019.
Understand.io is used by hundreds of Laravel developers to find and fix errors.
Sign up for a free 14-day trial now.