fix: allow text-columns to read a nested array value #14998
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When a Filament Text column reads a JSON attribute which contains a nested array, it throws an
Array to string conversion
exception.I tracked down the issue to occuring in
resources/views/columns/text-column.blade.php
, where thearrayState
is mapped and imploded. It goes through the given array and attempts to grab the value of each item. This works fine for single level arrays, as each value will be something stringable.However, if one of the values was an array (such as storing a list of integers), then the implode fails.
There is already a check for Filament Enums with Labels for the text column, and collections can be coerced into strings. This PR adds an additional check for if the value being mapped for implosion is an array and if so, then encode it into json. Additionally, it adds a return type to the closure to enforce that the map returns a nullable string.
Visual changes
Short example of data:
Before the Fix
After the Fix
Functional changes
composer cs
command.