Skip to content

Commit 34ca90c

Browse files
forwardDecoratedCallTo in Eloquent Builder __call to fix (#24)
* forwardDecoratedCallTo in Eloquent Builder __call to fix laravel/framework#56664 --------- Co-authored-by: Pantea Marius-ciclistu <>
1 parent da32f27 commit 34ca90c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Eloquent/CustomRelations/Builders/CleverEloquentBuilder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
class CleverEloquentBuilder extends Builder
2222
{
23+
protected mixed $lastForwardCallToReturn;
2324
protected bool $getUnHydrated = false;
2425

2526
/**
@@ -177,4 +178,28 @@ public function with($relations, $callback = null): static
177178

178179
return $this;
179180
}
181+
182+
/**
183+
* @inheritdoc
184+
*/
185+
public function __call($method, $parameters): mixed
186+
{
187+
unset($this->lastForwardCallToReturn);
188+
$result = parent::__call($method, $parameters);
189+
190+
if (isset($this->lastForwardCallToReturn)) {
191+
$result = $this->lastForwardCallToReturn === $this->query ? $this : $this->lastForwardCallToReturn;
192+
unset($this->lastForwardCallToReturn);
193+
}
194+
195+
return $result;
196+
}
197+
198+
/**
199+
* @inheritdoc
200+
*/
201+
protected function forwardCallTo($object, $method, $parameters): mixed
202+
{
203+
return $this->lastForwardCallToReturn = parent::forwardCallTo($object, $method, $parameters);
204+
}
180205
}

0 commit comments

Comments
 (0)