mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-01 15:09:33 +08:00
fix: fillForm() merges list state into existing repeater record keys (#19339)
When `fillForm()` is called with list-style arrays (numeric keys) on a
repeater that has loaded existing relationship records (`record-{id}`
keys), `unsetMissingNumericArrayKeys()` only removes orphaned numeric
keys but leaves the old `record-{id}` keys intact. This causes both
key sets to coexist, leading to data duplication on save.
Adding `array_is_list($state)` to the condition ensures that when the
new state is a sequential list, all non-matching keys are removed —
including `record-{id}` keys — giving `fillForm()` proper replacement
semantics for list arrays.
This commit is contained in:
@@ -90,7 +90,7 @@ trait InteractsWithForms
|
||||
protected function unsetMissingNumericArrayKeys(array &$target, array $state): void
|
||||
{
|
||||
foreach ($target as $key => $value) {
|
||||
if (is_numeric($key) && (! array_key_exists($key, $state))) {
|
||||
if ((is_numeric($key) || array_is_list($state)) && (! array_key_exists($key, $state))) {
|
||||
unset($target[$key]);
|
||||
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user