Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for new cursor method. #2434

Merged
merged 2 commits into from
Jul 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eloquent.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ If you need to process thousands of Eloquent records, use the `chunk` command. T

The first argument passed to the method is the number of records you wish to receive per "chunk". The Closure passed as the second argument will be called for each chunk that is retrieved from the database.

> **Note:** The database query is re-executed for each chunk.

#### Traversing Results

If you need to traverse records using a cursor, use the `cursor` command. The `cursor` method will allow you to simply loop over the result like an array. The `cursor` command returns an Eloquent model. Using the `cursor` method will reduce overhead and reduce memory allocation when processing and manipulating result sets:

foreach( Flight::where('foo', 'bar')->cursor() as $flight) {
//
});

<a name="retrieving-single-models"></a>
## Retrieving Single Models / Aggregates

Expand Down