Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit eeb5325

Browse files
committed
Merge branch 'main' into pr/466
2 parents f59a1dc + 56b5375 commit eeb5325

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Components/Form.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Form extends Component
3030

3131
private $json;
3232

33+
/** @var Model|null */
3334
private $model;
3435

3536
private static $defaultGuardAttributes = true;
@@ -42,6 +43,8 @@ class Form extends Component
4243

4344
private static $instances = [];
4445

46+
private $resolvedData = false;
47+
4548
/**
4649
* Create a new component instance.
4750
*
@@ -169,6 +172,20 @@ private function parseUnguardedValue($unguarded = null, $value = null)
169172
}
170173
}
171174

175+
/**
176+
* Returns the resolved data but evualates it only once.
177+
*/
178+
public function resolveData(): ?object
179+
{
180+
if ($this->resolvedData !== false) {
181+
return $this->resolvedData;
182+
}
183+
184+
$this->resolvedData = $this->guardedData() ?: $this->defaultData();
185+
186+
return $this->resolvedData;
187+
}
188+
172189
/**
173190
* This is a workaround for https://github.com/vuejs/core/issues/5339
174191
*
@@ -183,12 +200,10 @@ public static function selected(string $name, $value): bool
183200
return false;
184201
}
185202

203+
/** @var Form */
186204
$instance = Arr::last(static::$instances);
187205

188-
$data = data_get(
189-
$instance->guardedData() ?: $instance->defaultData(),
190-
static::dottedName($name)
191-
);
206+
$data = data_get($instance->resolveData(), static::dottedName($name));
192207

193208
return is_array($data)
194209
? in_array($value, $data, true)
@@ -403,7 +418,7 @@ private function defaultData(): ?object
403418
public function formData(): array
404419
{
405420
$data = [
406-
'data' => $this->guardedData() ?: $this->defaultData(),
421+
'data' => $this->resolveData(),
407422
'json' => $this->json,
408423
];
409424

0 commit comments

Comments
 (0)