F
Filament9mo ago
Samir

Problem showing array in Infolist using RepeatableEntry

I have Product table with 'syn' field which takes multiple entries. I am using repeater for this in form. Now, I am using View file where I want to see all my 'syn'. I am using below code in Infolist. RepeatableEntry::make('syn')->schema([ TextEntry::make('syn') )]. But it gives me list of empty entries. So if I have 11 entries, then it gives 11 empty blocks. I tried using RepeatableEntry::make('$this->product->syn') or RepeatableEntry::make('$this->product') both gave error. RepeatableEntry::make('syn') does not give error and also lists exact blocks for entries. But why data not populated. Please help. In my migration syn is json type and in Product model I have already cast it array. Form or Table view is great.
Solution:
You can simple display simple repeater json data like this ```php RepeatableEntry::make('syn') // syn is json column ->schema([ TextEntry::make('') // leave empty...
Jump to solution
12 Replies
josef
josef9mo ago
First off, you have to put the schema into a closure. There is a bug that leads to all entries being the first one. Secondly, if syn is an array, you should access to array entries in the TextEntries inside the repeater, no?
toeknee
toeknee9mo ago
Also please read #❓┊help on how to ask for help, your code needs formatting to start.
Samir
Samir9mo ago
Thanks @josef for the response. But I dint understand your second part. Thanks for pointing @toeknee . Here is my formatted code. ‘’’ RepeatableEntry::make('syn') ->schema([ TextEntry::make('syn'), ])->grid(2)’’’
toeknee
toeknee9mo ago
it should be formatted as per:
RepeatableEntry::make('syn')
->schema([
TextEntry::make('syn'),
])->grid(2)
RepeatableEntry::make('syn')
->schema([
TextEntry::make('syn'),
])->grid(2)
What is syn? If syn is returning a relationship or an array of data, the TextEntry should be the sub part
Samir
Samir9mo ago
thanks for pointing. I just joined yesterday. As mentioned 'syn' is a json field as it takes simple text entries using a repeater in a form. I have casted it to array in Product Model. It is not returning any relationship. 'syn' field stores all synonyms for a Product. I just want to show list of all synonyms in a responsive two column. I have long list of 20-50 synonyms for a Product.
toeknee
toeknee9mo ago
That's fine, but you have syn syn. Wouldn't it be more: syn (as the json field) then 'name' for the syn?
Samir
Samir9mo ago
I am using Simple Repeater as one of the Repeater feature in Filament3 which can be used if entries are simple. Would you mind recommending best approach accepting and populating it in Infolist. I am just 1 month in Laravel and filament. I uses 'syn' 'syn' because that what i could understand to use RepeatableEntry for populating.
awcodes
awcodes9mo ago
This also probably shouldn’t be a json column since json requires a key and simple is looking for a non keyed array.
Samir
Samir9mo ago
Even if I keep different names in Simple Repeater, my results are same. Now I changed TextEntry under Simple Repeater from 'syn' to 'synonym_name'. Interesting part is My Table view and Form views are fine. I can even store this array in a different variable and run foreach loop to show in whatever way I can. However, Its not working as expected in Infolist RepeatableEntry. I even changed my data type in migration file from JSON to longText.
Solution
Vp
Vp9mo ago
You can simple display simple repeater json data like this
RepeatableEntry::make('syn') // syn is json column
->schema([
TextEntry::make('') // leave empty
])
RepeatableEntry::make('syn') // syn is json column
->schema([
TextEntry::make('') // leave empty
])
Samir
Samir9mo ago
Thanks alot. It worked like a charm. Thanks alot @Vp .