Skip to content

Commit 47fed28

Browse files
committed
wip
1 parent a77d8e7 commit 47fed28

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

eloquent-relationships.md

+8
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,14 @@ foreach ($users as $user) {
22832283

22842284
Typically, the code above would execute a query for each user in order to retrieve their posts, as well as a query for each post to retrieve its comments. However, when the `automaticallyEagerLoadRelationships` feature has been enabled, Laravel will automatically [lazy eager load](#lazy-eager-loading) the posts for all users in the user collection when you attempt to access the posts on any of the retrieved users. Likewise, when you attempt to access the comments for any retrieved post, all comments will be lazy eager loaded for all posts that were originally retrieved.
22852285

2286+
If you do not want to globally enable automatic eager loading, you can still enable this feature for a single Eloquent collection instance by invoking the `withRelationshipAutoloading` method on the collection:
2287+
2288+
```php
2289+
$users = User::where('vip', true)->get();
2290+
2291+
return $users->withRelationshipAutoloading();
2292+
```
2293+
22862294
<a name="preventing-lazy-loading"></a>
22872295
### Preventing Lazy Loading
22882296

0 commit comments

Comments
 (0)