mutateRelationshipDataBeforeCreateUsing in Filament's Repeater supposed to return an array of items?

Isn't the mutateRelationshipDataBeforeCreateUsing callback in Filament's Repeater component supposed to return an array of items (or a list of arrays) instead of a single associative array? Here is my code: ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { dd($data); $tenant = Filament::getTenant(); foreach ($data as &$item) { $item['organization_id'] = $tenant->id; } return $data; }) When I use dd($data), I expect to see a list of arrays (one for each Repeater item). However, I only see a single associative array containing fields from the first item only. array:7 [▼ // app/Filament/Resources/InvoiceResource.php:244 "product_id" => "3" "quantity" => 4 "unit_price" => 12 ] Shouldn't $data be a list of the Repeater's items rather than the first item's fields? If this is expected behavior, how can I properly manipulate Repeater data at this stage? Could this potentially be a bug?
Solution:
So it looks like there is no need to iterate through the data https://github.com/filamentphp/filament/discussions/4485#discussioncomment-3851865 `->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $tenant = Filament::getTenant();...
GitHub
Mutating using mutateRelationshipDataBeforeCreateUsing only retur...
When I am trying to mutate my repeater data before saving it, I only ever get one (the first) element returned (even though there are many repeated fields). Repeater::make('repeats') ->m...
Jump to solution
3 Replies
Epko
Epko4w ago
Never used this, but I think the method is called separately for each entry. So dd() would only show the first one.
xoshbin
xoshbinOP4w ago
mutateRelationshipDataBeforeAddUsing() should be chained onto the Repeater field directly https://github.com/filamentphp/filament/issues/5775#issuecomment-1445288042
GitHub
mutateFormDataBeforeCreate does not returns relations data of form ...
Package filament/filament Package Version 2.16 Laravel Version 9.52 Livewire Version No response PHP Version 8.1 Problem description There is relationship like BelongsToMany in order model. To fetc...
Solution
xoshbin
xoshbin4w ago
So it looks like there is no need to iterate through the data https://github.com/filamentphp/filament/discussions/4485#discussioncomment-3851865 ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $tenant = Filament::getTenant(); $data['organization_id'] = $tenant->id; return $data; })
GitHub
Mutating using mutateRelationshipDataBeforeCreateUsing only retur...
When I am trying to mutate my repeater data before saving it, I only ever get one (the first) element returned (even though there are many repeated fields). Repeater::make('repeats') ->m...
Want results from more Discord servers?
Add your server