Convert Repeater to a Multiple Select Field
I have a 'postCategories' Pivot relationship. I already prepared the Models and Relationships as they mentioned in the Doc. The repeater works fine as expected. Is there any way to convert this Repeater field to a multiple-select field? So then it's looks cleaner than a repeater. Because i don't have extra data fields on my pivot table. Just 'post_id' and 'category_id'.
12 Replies
You have a post and you want to select multiple categories? If that's the case a CheckboxList would be a nice solution as well https://filamentphp.com/docs/3.x/forms/fields/checkbox-list but if you have lots of categories maybe use 1 select with multiple options like this https://filamentphp.com/docs/3.x/forms/fields/select#multi-select
This is my form input fiedl and it's give me an error saying
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'post_categories.' in 'field list'
. This is my Model Configurations to my Pivot table using a pivot Model. @Tally
In my Post Model
In my Pivot Table Model (PostCategory)
When creating a Post i want to let the user to select multiple categories using a select field.Solution
The categories must be a BelongsToMany?
wait... you don't need the PostCategory pivot at all
if you change the categories() to a BelongsToMany of your Category::class it will work
I only needed to specify a title in my relationship to get it to work:
Can you check this section on repeater ? https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship
I see it... never needed it though 😉
Let me try your solution fast
I'm not really using it with a repeater... was using the CheckboxList... converted it to a Select and it worked
It's work fine bro. How can i show that details on Post table as badges? Can you help me with that too...
This works for me
Got that too. Thanks in advace 💌 @Tally
you're welcome!