From d287dcf04b9091a9bcc0a7ec90cb53e11a359fd6 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Sep 2021 12:39:26 -0400 Subject: [PATCH 1/3] [8.x] Add forwardDecoratedCallTo --- .../Database/Eloquent/Relations/Relation.php | 8 +------ .../Support/Traits/ForwardsCalls.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Relation.php b/src/Illuminate/Database/Eloquent/Relations/Relation.php index afb5ba8aea08..445778d4716e 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/src/Illuminate/Database/Eloquent/Relations/Relation.php @@ -478,13 +478,7 @@ public function __call($method, $parameters) return $this->macroCall($method, $parameters); } - $result = $this->forwardCallTo($this->query, $method, $parameters); - - if ($result === $this->query) { - return $this; - } - - return $result; + return $this->forwardDecoratedCallTo($this->query, $method, $parameters); } /** diff --git a/src/Illuminate/Support/Traits/ForwardsCalls.php b/src/Illuminate/Support/Traits/ForwardsCalls.php index 8b7add869689..5e928da883a4 100644 --- a/src/Illuminate/Support/Traits/ForwardsCalls.php +++ b/src/Illuminate/Support/Traits/ForwardsCalls.php @@ -37,6 +37,29 @@ protected function forwardCallTo($object, $method, $parameters) } } + /** + * Forward a method call to the given object, returning $this if + * the forwarded call returned itself (was fluent). + * + * @param mixed $object + * @param string $method + * @param array $parameters + * + * @return mixed + * + * @throws \BadMethodCallException + */ + protected function forwardDecoratedCallTo($object, $method, $parameters) + { + $result = $this->forwardCallTo($object, $method, $parameters); + + if ($result === $object) { + return $this; + } + + return $result; + } + /** * Throw a bad method call exception for the given method. * From 77b51374614e8ced1ea9f691ecb6f01347d0554e Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Sep 2021 13:02:44 -0400 Subject: [PATCH 2/3] Code style --- src/Illuminate/Support/Traits/ForwardsCalls.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Support/Traits/ForwardsCalls.php b/src/Illuminate/Support/Traits/ForwardsCalls.php index 5e928da883a4..48e74e93a436 100644 --- a/src/Illuminate/Support/Traits/ForwardsCalls.php +++ b/src/Illuminate/Support/Traits/ForwardsCalls.php @@ -44,7 +44,6 @@ protected function forwardCallTo($object, $method, $parameters) * @param mixed $object * @param string $method * @param array $parameters - * * @return mixed * * @throws \BadMethodCallException From b5238a443b5256e885cb643acabe063b346d704a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 Sep 2021 13:43:30 -0500 Subject: [PATCH 3/3] Update ForwardsCalls.php --- src/Illuminate/Support/Traits/ForwardsCalls.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Traits/ForwardsCalls.php b/src/Illuminate/Support/Traits/ForwardsCalls.php index 48e74e93a436..e7181809804f 100644 --- a/src/Illuminate/Support/Traits/ForwardsCalls.php +++ b/src/Illuminate/Support/Traits/ForwardsCalls.php @@ -38,8 +38,7 @@ protected function forwardCallTo($object, $method, $parameters) } /** - * Forward a method call to the given object, returning $this if - * the forwarded call returned itself (was fluent). + * Forward a method call to the given object, returning $this if the forwarded call returned itself. * * @param mixed $object * @param string $method