Fill repeater in custom form in modal
Hello, to begin with, this is a semi long question/issue, and I honestly was not feeling good about posting it and possibly have someone willing to help read through the whole thing. So I think that the fair thing to do would be to buy someone coffee/beer/your drink of choice or sponsor them if available.
I am working with a table using actions, and when clicking on the action, it opens up a modal which has a custom form in it. The form has some text inputs which I am filling in and showing them as disabled. So far so good here. Then I am using a table-repeater and I am trying to pre-fill it as well. Here is where the issues start for me. The table rows need to show data from a relationship. My models are Package and Document where Package has a hasMany with Document and Document has a belongsTo with Package. All the data related to Package is fine but I have not been able to fill the table-repeater with as many rows as the package has documents, and fill the document_type_id TextInput. Finally, on the more complicated part (for me), retrieve the image from s3 (image name is on a column on the Documents table ).
Here is my gist of what the code looks like right now:
https://gist.github.com/rgut13rrez/2275aec31e0d5120cf6da4fbfab378fe
Gist
filament table with actions/modal/form/table-repeater
filament table with actions/modal/form/table-repeater - PackagesTable.php
12 Replies
hey, is there a relationship() method on the table repeater?
if it extends our core Repeater, then you will be able to load and save items with just that line
It is not on the code I shared but it was one of the things I tried earlier... but then I went down a rabbit hole with other things I changed trying to get the FileUpload to work so I just started from the part I shared. Let me look at that again using ->relationship() at least to load document_type_id first
I thought I had it working with this but for some reason it is not loading the display_name into the document_type_name TextInput. If I dd($document), I do see the relation Document->DocumentType. Probably something basic I am not seeing.
Action::make('editPackage')
->mountUsing(fn (Forms\ComponentContainer $form, Package $record) => $form->fill([
'package_name' => $record->name,
'number_of_documents' => $record->number_of_documents,
'state_name' => $record->jurisdiction->state->name,
'jurisdiction_name' => $record->jurisdiction->name,
'documents' => $record->documents->map(function ($document) {
return [
'document_type_name' => $document->documentType->display_name,
dd($document)
];
})->toArray(),
]))
The TableRepeated does extend your core repeater and I am using relationship() nowyou do not need documents in the array
we can infer that for you
im skeptical about document_type_name not being a 1:1 map with the actual columns in the table? how will that work?
is it a read-only placeholder?
you mean the columns in the database under the document_types table?
repeater fields usually match 1:1 with the columns in the table
so
$document->document_type_name
yeah, so I also tried with the same name which is display_name
but its on a relationship
Oh, I see what you mean...hmmm
is this a read-only field in the repeater
if so, you can probably just use a Placeholder and you dont need to worry about it being filled
Yeah, it should be read only so I put it as a disabled TextInput to try to keep the same UI look when compared to a the standalone create form I have... but I suppose it does not need to be an input and placeholder would work
I mean still input but with placeholder
Well well well... this works like a charm and it ends up being way better for my needs. I really appreciate your help. I have been using filament for about 2 -3 weeks now, and it just continues to amaze me every single day. Thanks again.