Skip to content

Commit

Permalink
[8.x] Add forwardDecoratedCallTo (laravel#38800)
Browse files Browse the repository at this point in the history
* [8.x] Add forwardDecoratedCallTo

* Code style

* Update ForwardsCalls.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
2 people authored and chu121su12 committed Sep 14, 2021
1 parent b919fa9 commit f39badd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,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);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/Illuminate/Support/Traits/ForwardsCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ protected function forwardCallTo($object, $method, $parameters)
}
}

/**
* Forward a method call to the given object, returning $this if the forwarded call returned itself.
*
* @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.
*
Expand Down

0 comments on commit f39badd

Please sign in to comment.