Skip to content

Conversation

@mikemartin
Copy link

@mikemartin mikemartin commented Jan 5, 2026

Replaces mergeRecursive() with replaceRecursive() when combining initial form data and extra data. This prevents scalar values from being merged into arrays (for example [null, 'apple']) while still preserving nested form structures.

Using mergeRecursive():

$initialFormData = [
    'fruit' => null
    'quantity' => 1,
];

$extraData = [
    'fruit' => 'apple',
    'quantity' => 2,
];

return [
  'x-data' => $this->renderAlpineXData(collect($initialFormData())->mergeRecursive($extraData)->all(), $this->scope),
];

// [
//     'fruit' => [null, 'apple'],
//     'quantity' => [1, 2],
// ]

Using replaceRecursive():

$initialFormData = [
    'fruit' => null
    'quantity' => 1,
];

$extraData = [
    'fruit' => 'apple',
    'quantity' => 2,
];

return [
  'x-data' => $this->renderAlpineXData(collect($initialFormData())->replaceRecursive($extraData)->all(), $this->scope),
];

// [
//     'fruit' => ['apple'],
//     'quantity' => [2],
// ]

@mikemartin mikemartin changed the title Correct recursive form data merging [6.x] Correct recursive form data merging Jan 5, 2026
@duncanmcclean
Copy link
Member

Are you able to resolve the merge conflicts?

@mikemartin
Copy link
Author

@duncanmcclean Should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants