Skip to content

Conversation

@iotron
Copy link
Contributor

@iotron iotron commented Dec 17, 2025

Summary

Fixes #18726

When Repeater's afterStateHydrated restructures items with UUID keys, it calls rawState() which triggers clearCachedDefaultChildSchemas(). Subsequent calls to getItems() create new child schemas that haven't been through hydrateState(), so StateCasts (like FileUploadStateCast) are never applied.

This causes FileUpload components inside non-relationship Repeaters (JSON columns) to fail with:

foreach() argument must be of type array|object, string given

The error occurs because FileUpload::getUploadedFiles() expects UUID-keyed arrays but receives raw strings.

Solution

Apply StateCasts to child components after creating schemas in getItems() for non-relationship repeaters. The existing castStateAfterLoadingFromRelationships() method handles this perfectly - it recursively processes child schemas and is idempotent.

For relationship-based repeaters, this is already handled via loadStateFromRelationships(shouldHydrate: true).

Test Plan

  • Create a Repeater with FileUpload inside a JSON column (not relationship-based)
  • Upload an image and save
  • Reload the form - previously crashed, now works correctly

When Repeater's afterStateHydrated restructures items with UUID keys,
it calls rawState() which triggers clearCachedDefaultChildSchemas().
Subsequent calls to getItems() create new child schemas that haven't
been through hydrateState(), so StateCasts (like FileUploadStateCast)
are never applied.

This fix applies StateCasts to child components after creating schemas
in getItems() for non-relationship repeaters. This ensures FileUpload
and other StateCast-dependent components have properly normalized state.

Fixes filamentphp#18726
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Dec 17, 2025
@danharrin danharrin added the bug Something isn't working label Dec 22, 2025
@danharrin danharrin added this to the v4 milestone Dec 22, 2025
@danharrin
Copy link
Member

Can you please submit a reproduction repository for this issue @iotron so I can investigate myself and also test that your fix works?

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

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

FileUpload (and other StateCast components) inside Repeater with JSON column throws "foreach() argument must be of type array|object, string given"

2 participants