TableRepeater / Repeater populating form

Trying to use the TableRepeater plugin and it's working great except I have rows in my database that I want to populate the form with, and I can't seem to get it to do that. I must be missing something. This is an edit modal action on a table row, if that's matters. So the user clicks the table row's edit button, which brings up a modal that should display all the line items of the parent row in the TableRepeater.
Action::make('customEdit')
->model(AutomatedSalesJournalEntryHeader::class)
->form([
TableRepeater::make('lines')
->relationship()
->streamlined()
->headers([
Header::make('Account')->width('200px'),
Header::make('Debits')->width('100px'),
Header::make('Credits')->width('100px'),
Header::make('Description')->width('150px'),
])
->schema([
Select::make('account_ref_id')
->required()
->options(fn() => $this->accounts)
TextInput::make('amount')
->required(),
...
])
]),
Action::make('customEdit')
->model(AutomatedSalesJournalEntryHeader::class)
->form([
TableRepeater::make('lines')
->relationship()
->streamlined()
->headers([
Header::make('Account')->width('200px'),
Header::make('Debits')->width('100px'),
Header::make('Credits')->width('100px'),
Header::make('Description')->width('150px'),
])
->schema([
Select::make('account_ref_id')
->required()
->options(fn() => $this->accounts)
TextInput::make('amount')
->required(),
...
])
]),
Solution:
ok, that's helpful. It didn't work with fillFormUsing, but there's a fillForm method and that worked! ```php ->fillForm(function (AutomatedSalesJournalEntryHeader $record) { return [ 'lines' => $record->lines->map(function (AutomatedSalesJournalEntryLine $line) {...
Jump to solution
6 Replies
toeknee
toeknee4w ago
Is the relationship lines a hasMany relationship?
Jon Mason
Jon MasonOP4w ago
it is
toeknee
toeknee4w ago
I have a feeling you likely need to fillFormUsing() with finding the record then You might expect model to do that, but it won't know where to find the data.
Solution
Jon Mason
Jon Mason4w ago
ok, that's helpful. It didn't work with fillFormUsing, but there's a fillForm method and that worked!
->fillForm(function (AutomatedSalesJournalEntryHeader $record) {
return [
'lines' => $record->lines->map(function (AutomatedSalesJournalEntryLine $line) {
return [
'account_ref_id' => $line->account_ref_id,
'amount' => $line->amount,
'description' => $line->description,
];
})->toArray(),
];
})
->fillForm(function (AutomatedSalesJournalEntryHeader $record) {
return [
'lines' => $record->lines->map(function (AutomatedSalesJournalEntryLine $line) {
return [
'account_ref_id' => $line->account_ref_id,
'amount' => $line->amount,
'description' => $line->description,
];
})->toArray(),
];
})
Jon Mason
Jon MasonOP4w ago
Thanks!
toeknee
toeknee4w ago
Ahh that's the ticket. Well done!

Did you find this page helpful?