Programmatically fill repeaters in EditRecord page
Is there a way to fill repeaters in an EditRecord page with some values ?
Using
->default()
is only possible on a CreateRecord page IIRC.
I've tried directly using
but nothing gets added to the repeater, and if i dd()
the form raw state right after, this is what i get :
11 Replies
We have a tutorial about it: https://laraveldaily.com/post/filament-repeater-set-values-manually-other-fields
form gets filled by filament. I believe you should use
mutateFormDataBeforeFill()
or hooks
check the source code for the edit page how it is filled https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Resources/Pages/EditRecord.php#L104I've tried the
$form->fill()
and the mutateFormDataBeforeFill()
, but my repeated field array just get emptied
Update : i've realised that this is working if i don't use ->relationship()
on my repeater. Any idea on why the relationship would break that ?Filament tries to get data from a relationship I guess
Yep, it looks like it. Maybe i'm not using the right pattern to begin with ?
I want, from an already existing filament resource, to be able to create items through a HasMany relationship, with a pre-defined repeater of 3 items and some pre filled attributes.
Do you think extending EditRecord suits this ? (I'm doing this right now)
For me it's weird that you are doing this on the edit page
Not sure if this helps, but i have a custom action with a repeater that gets filled this way.
Thank you for your snippet, i think this would work great if i need to edit them, unfortunately i'm not sure how to use it to 'create' new repeater items
Wouldn't that just be?
Edit: Never mind this is on the create π
It's weird how you want to use it. Maybe give more context and code
Thank you all for your help, I ended up removing the relationship and using
handleRecordUpdate
to manage my update