What is the purpose of the Eloquent cursor() method in Laravel ?

Technology CommunityCategory: LaravelWhat is the purpose of the Eloquent cursor() method in Laravel ?
VietMX Staff asked 3 years ago

The cursor method allows you to iterate through your database records using a cursor, which will only execute a single query. When processing large amounts of data, the cursor method may be used to greatly reduce your memory usage.

foreach (Product::where('name', 'bar')->cursor() as $flight) {
   //do some stuff
}