F
Filamentβ€’15mo ago
Nils Domin

How do I count the saved elements of a form's Repeater Field in a table column?

In my form I have a Repeater field which saves data as json (cast to array in model). Now I want to show the count of these items from this json column in my table, for example with a TextColumn. How do I achieve that? If I try with formatStateUsing...I always get the error Array to string conversion, no matter what I try .
Solution:
Maybe try getStateUsing? You should then be able to use a different column name, which doesn't have to exist on the table, and do whatever you need based on the $record ... ```php TextColumn::make('yourjson_count') ->getStateUsing(Model $record) => count($record->yourjson')),...
Jump to solution
2 Replies
Solution
cheesegrits
cheesegritsβ€’15mo ago
Maybe try getStateUsing? You should then be able to use a different column name, which doesn't have to exist on the table, and do whatever you need based on the $record ...
TextColumn::make('yourjson_count')
->getStateUsing(Model $record) => count($record->yourjson')),
TextColumn::make('yourjson_count')
->getStateUsing(Model $record) => count($record->yourjson')),
Nils Domin
Nils DominOPβ€’15mo ago
Yeah, I haven't thought about getStateUsing... thank you very much, it works now! πŸ˜ƒ
Want results from more Discord servers?
Add your server