Skip to content

Commit 17e445a

Browse files
[8.x] Add withOnly method (#37144)
* Added in new withOnly method + tests * Refactored function * Update Builder.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 7f8703b commit 17e445a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Eloquent/Builder.php

+13
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,19 @@ public function without($relations)
12361236
return $this;
12371237
}
12381238

1239+
/**
1240+
* Set the relationships that should be eager loaded while removing any previously added eager loading specifications.
1241+
*
1242+
* @param mixed $relations
1243+
* @return $this
1244+
*/
1245+
public function withOnly($relations)
1246+
{
1247+
$this->eagerLoad = [];
1248+
1249+
return $this->with($relations);
1250+
}
1251+
12391252
/**
12401253
* Create a new instance of the model being queried.
12411254
*

0 commit comments

Comments
 (0)