-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[6.x] Add an eager()
method to the lazy collection class
#29832
Conversation
The naming of this and when to even use it are still very murky to me. 😄 |
What about |
Do you understand when a user would want to call
// These two end up doing the same thing:
$lazyCollection = $lazyCollection()->collect()->lazy();
$lazyCollection = $lazyCollection()->eager(); |
Would |
Yeah, I'm not a fan of the name |
Definitely prefer |
3f11fce
to
a2c2682
Compare
eager()
method to the lazy collection class
Updated. |
…9832) * Add a cache() method to the lazy collection class * Rename `cache` method to `eager`
The
eager()
method enumerates all of the lazy collection's values, and constructs a newLazyCollection
instance, which will now be backed by an array:The above will only fetch the users once. Without calling
eager
in between, the query would execute (and fetch all results) twice.This is a pretty useless example, but is a clear illustration of what the
eager
method does.