Skip to content

Commit

Permalink
prevent multiple hydration from 'old' value
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 20, 2023
1 parent fd15910 commit 09f01c5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ abstract class Field implements Arrayable, JsonSerializable
*/
protected ?string $apiUri = null;

/**
* Indicates if the field has been hydrated.
*/
protected bool $hydrated = false;

/**
* Create a new field instance.
*/
Expand Down Expand Up @@ -274,9 +279,11 @@ public function suffix(string $value): static
*/
public function resolveValue(Request $request, Model $model): mixed
{
$value = $this->withOldValue && $request->session()->hasOldInput($this->getRequestKey())
? $this->getOldValue($request)
: $this->getValue($model);
if (! $this->hydrated && $this->withOldValue && $request->session()->hasOldInput($this->getRequestKey())) {
$this->resolveHydrate($request, $model, $this->getOldValue($request));
}

$value = $this->getValue($model);

if (is_null($this->valueResolver)) {
return $value;
Expand Down Expand Up @@ -351,6 +358,8 @@ public function resolveHydrate(Request $request, Model $model, mixed $value): vo
}

call_user_func_array($this->hydrateResolver, [$request, $model, $value]);

$this->hydrated = true;
}

/**
Expand Down

0 comments on commit 09f01c5

Please sign in to comment.