Select multiple issue
I have this issue where I select certain people, save, and the order seems correct in the selection. After refreshing, the order changes. Do you have any idea what could be causing this?
27 Replies
Please show some code.
Is it a relationship?
and the model
Yes, it's a relationship
As long as there is no
orderBy
I don't think there is any guaranteed ordering.Where should I put orderBy?
You can either order your relationship (if you always want it ordered) or you can pass a 3rd param to
relationship()
to adjust the queryAnd will this change maintain the order of the elements based on how they are selected?
Not sure if they are saved in the order you add them. You could order them by their pivot id. But might not work
In this case, would it be a better option to use a repeater with a select inside it instead of this multiple select?
If you really need to the order in which they were added you probably need a JSON column or a relationship that has a order column
Ok, thank you for your help
One more question, please. I've added an "order" column to my pivot table "guest_staff". Is it possible to create a checkbox list with a select staff relationship and also, for all the staff person to have a field where to add the order?
I did in this way, but the repeater displays only the last item
Why do you use a TableRepeater instead of a Repeater with
orderable()
?I added this now but can't reorder the repeater items and still see only the last or the first item, although in the db I have all the items
Should give you an error actually, since it's
->reorderable()
. Check the docs on reodering: https://filamentphp.com/docs/3.x/forms/fields/repeater#reordering-items
still see only the last or the first itemCan you share the code for
guestExperienceStaff
relationship? I am using Filament v2
That's the Pivot class. But what is the relationship definition on your model?
sorry
Can you check what the relation returns somewhere in your Laravel app or in Tinker:
Hm. Looks good. What's the current Repeater code?
I only removed the orderable()
Also looks good. No idea why it only shows one
guestExperienceStaff
Can you show a screenshot?No idea what's happening sorry. Is your v2 version up-to date?
yes, is up to date 😅
I believe the issue is caused by the fact that a new entry is being created in the table for each person, instead of a single JSON entry as the Repeater normally functions
No, that's how it should be. It's a relation
Yes, I know that this is how data is normally added for relationships. However, I thought that it might not be suitable for the Repeater in this case