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

2019-12-10 16:17:04 Alia Laravel

Eloquent cursor()

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.

Example Usage

foreach (Product::where('name', 'bar')->cursor() as $flight) {

 //do some stuff

}


This post is submitted by one of our members. You may submit a new post here.

Related Tricks