How to Edit the Data of a Repeater
How do I modify the data of a repeater? In my model, a category has subcategories, and a warehouse has locations.
For the form, I managed to load the subcategories based on the selected category and to load the locations after selecting the warehouse.
Then, a product has a subcategory (based on this, I get the category) and multiple locations (based on each location, I should get the warehouse). In the edit mode, I’ve already managed to load the category based on the subcategory, but I can’t load the warehouses based on the locations. How could I do that? Thanks in advance.
5 Replies
I tried to analyze how the data from a repeater is sent, but I realized that when I click 'create', only the base model data is sent, and I don’t see the repeater data or that many-to-many relationship.
If the repeater is sent as a relationship they are parsed differently with their own mutateBeforeCreate method.
Thank you very much, I did this to test:
I added several records in the repeater, so I expected to see something like this:
But it only shows this:
Meaning, it only shows the first one and seems to ignore the rest.
I also tried altering it:
And what I achieved was that when editing, every record in the repeater gets set to those values.
I tested the methods
mutateRelationshipDataBeforeSaveUsing()
, mutateRelationshipDataBeforeFillUsing()
, and mutateRelationshipDataBeforeCreateUsing()
in the Filament demo. I tested them in App\Filament\Resources\Shop\OrderResource
. On line 357, I added:
And it always returns only the data from the first item of the repeater, like this:
Even though there are several items, it only returns 1, and it is always the first item of all.Actually mutate runs on each item, because it’s before create. It creates each item and runs and can be conditioned for each item.
You could pass in a Get $get to the function after $data and then get the repeater itself if you wanted all the data