Skip to content

Commit

Permalink
[5.x] Fix using hook as field name (#10319)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Jun 18, 2024
1 parent f5ab7c4 commit a16223b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Data/AbstractAugmented.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function get($handle): Value

if ($this->methodExistsOnThisClass($method)) {
$value = $this->wrapAugmentedMethodInvokable($method, $handle);
} elseif (method_exists($this->data, $method) && collect($this->keys())->contains(Str::snake($handle))) {
} elseif ($this->methodExistsOnData($handle, $method)) {
$value = $this->wrapDataMethodInvokable($method, $handle);
} else {
$value = $this->wrapDeferredValue($handle);
Expand All @@ -90,11 +90,18 @@ private function excludedKeys()
: [];
}

private function methodExistsOnThisClass($method)
private function methodExistsOnThisClass(string $method): bool
{
return method_exists($this, $method) && ! in_array($method, ['select', 'except']);
}

private function methodExistsOnData(string $handle, string $method): bool
{
return method_exists($this->data, $method)
&& collect($this->keys())->contains(Str::snake($handle))
&& ! in_array($handle, ['hook']);
}

protected function getFromData($handle)
{
$value = method_exists($this->data, 'value') ? $this->data->value($handle) : $this->data->get($handle);
Expand Down

0 comments on commit a16223b

Please sign in to comment.