Skip to content

Commit a84a2ed

Browse files
[8.x] Add forwardDecoratedCallTo (#38800)
* [8.x] Add forwardDecoratedCallTo * Code style * Update ForwardsCalls.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 55d3f78 commit a84a2ed

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/Illuminate/Database/Eloquent/Relations/Relation.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,7 @@ public function __call($method, $parameters)
478478
return $this->macroCall($method, $parameters);
479479
}
480480

481-
$result = $this->forwardCallTo($this->query, $method, $parameters);
482-
483-
if ($result === $this->query) {
484-
return $this;
485-
}
486-
487-
return $result;
481+
return $this->forwardDecoratedCallTo($this->query, $method, $parameters);
488482
}
489483

490484
/**

src/Illuminate/Support/Traits/ForwardsCalls.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ protected function forwardCallTo($object, $method, $parameters)
3737
}
3838
}
3939

40+
/**
41+
* Forward a method call to the given object, returning $this if the forwarded call returned itself.
42+
*
43+
* @param mixed $object
44+
* @param string $method
45+
* @param array $parameters
46+
* @return mixed
47+
*
48+
* @throws \BadMethodCallException
49+
*/
50+
protected function forwardDecoratedCallTo($object, $method, $parameters)
51+
{
52+
$result = $this->forwardCallTo($object, $method, $parameters);
53+
54+
if ($result === $object) {
55+
return $this;
56+
}
57+
58+
return $result;
59+
}
60+
4061
/**
4162
* Throw a bad method call exception for the given method.
4263
*

0 commit comments

Comments
 (0)