From a799c25e429fb89377e9521394d350c21f98209c Mon Sep 17 00:00:00 2001 From: Mahmoud Mohamed Ramadan <48416569+mahmoudmohamedramadan@users.noreply.github.com> Date: Fri, 3 Jun 2022 01:20:45 +0200 Subject: [PATCH 1/2] Adds `withoutEagerLoad` function --- src/Illuminate/Database/Eloquent/Builder.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index b152d138c22e..8aea13a8b8b6 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1573,6 +1573,19 @@ public function setEagerLoads(array $eagerLoad) return $this; } + + /** + * Flush the given relationships being eagerly loaded. + * + * @param array $relations + * @return $this + */ + public function withoutEagerLoad($relations) + { + $relations = array_diff(array_keys($this->model->getRelations()), $relations); + + return $this->with($relations); + } /** * Flush the relationships being eagerly loaded. From dbdf4de60149d7b48b2267f3ddae83c5c723805a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 3 Jun 2022 08:40:33 -0500 Subject: [PATCH 2/2] Update Builder.php --- src/Illuminate/Database/Eloquent/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 8aea13a8b8b6..d835fbbe868b 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1575,12 +1575,12 @@ public function setEagerLoads(array $eagerLoad) } /** - * Flush the given relationships being eagerly loaded. + * Indicate that the given relationships should not be eagerly loaded. * * @param array $relations * @return $this */ - public function withoutEagerLoad($relations) + public function withoutEagerLoad(array $relations) { $relations = array_diff(array_keys($this->model->getRelations()), $relations);