(Beginner question) Repeater - Formatting the output after update
On the
Repeater
, I want to be able to display how they will appear in the live view using the Textarea
below.
In the screenshot example, I want to change it to be:
Idina Menzel (Elphaba), Kristen Chenoweth (Glinda)
and display that in the Cast
field below.
I also want to save the data in Cast
to the database, rather than using the Repeater
data directly.Solution:Jump to solution
@Pekempy but if you save only the Cast to the database, then your Edit form would not work with Repeater, I don't think it's a good decision.
And with filling in the Cast, use the
afterStateUpdated()
method probably. Maybe you are already doing that, but you haven't shown any code, so hard to comment....9 Replies
Does βcastβ exist as a field on the model?
Solution
@Pekempy but if you save only the Cast to the database, then your Edit form would not work with Repeater, I don't think it's a good decision.
And with filling in the Cast, use the
afterStateUpdated()
method probably. Maybe you are already doing that, but you haven't shown any code, so hard to comment.Hm that's true - So I should store the cast_list_entries into the table as a json perhaps?
Issue there is I have a lot of legacy data which I'm importing so I'd have to build the json for them all in the importer too π€
well yeah, I guess it's part of the job of working with legacy data that you may want to still work in the future
This is my repeater / textarea in the resource currently
yeah I'll have a look at storing this and how its formatted and work on the legacy. and afterStateUpdated too, thank you!
Got a small issue with the loading on the edit page - seems to be pilling the REpeater Selects with the ID of the performer/character, rather than the name. It works perfectly on the Create page though π€
Maybe you will get some ideas from here: https://laraveldaily.com/post/filament-repeater-set-values-manually-other-fields
But also, it depends on how exactly do you save that json in the table
Thanks, I'll take a look.
It's storing just as
[{"status": "swing", "character": "5", "performer": "48"}]
And in the model:
Seems to work loading the label if I use Performer::pluck->('name','id'), but with thousands that's a bit slow. For character I have added a query for the show_id but unable to do that on the performer π€
Solved with:
->getOptionLabelUsing(fn($value): ?string => Performer::find($value)?->name)