I would like to know what is the difference between laravel chunk and laravel cursor method. Which method is more suitable to use? What will be the use cases for both of them? I know that you should use cursor to save memory but how it actually works in the backend?
A detailed explanation with example would be useful because I have searched on stackoverflow and other sites but I didn't found much information.
Here is the code snippet's from the laravel documentation.
Chunking Results
Flight::chunk(200, function ($flights) {
foreach ($flights as $flight) {
//
}
});
Using Cursors
foreach (Flight::where('foo', 'bar')->cursor() as $flight) {
//
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…