F
Filament11mo ago
biber

Mutate Repeater Data from Action

Hello, I want to mutate my Repeater data by inserting data from an import action on the model's resource edit page. In my models resource I have declared a form with a Repeater
Repeater::make('products')
->relationship()
->schema([
// ...
]);
Repeater::make('products')
->relationship()
->schema([
// ...
]);
The edit page has the following action:
protected function getActions(): array
{
return [
Action::make('import')
->label('Import Products')
->action(function (ComponentContainer $form) {
$formData = $form->getState();

$productImport = (new ProductImport);
$products = $productImport->import($formData['file'])->getProducts();

// $set('products', $products) ???
})
->form([
Forms\Components\FileUpload::make('file'),
]);
];
}
protected function getActions(): array
{
return [
Action::make('import')
->label('Import Products')
->action(function (ComponentContainer $form) {
$formData = $form->getState();

$productImport = (new ProductImport);
$products = $productImport->import($formData['file'])->getProducts();

// $set('products', $products) ???
})
->form([
Forms\Components\FileUpload::make('file'),
]);
];
}
How can I now fill the repeater with the gathered products? The callable $set('products', $products) does not work sadly (with adding the Closure to the function). Your help is appreciated!
Solution:
Solved it via
$this->form->getFlatFields()['products']->state($products);
$this->form->getFlatFields()['products']->state($products);
...
Jump to solution
1 Reply
Solution
biber
biber11mo ago
Solved it via
$this->form->getFlatFields()['products']->state($products);
$this->form->getFlatFields()['products']->state($products);
It works, but maybe not the best way to do. :)
Want results from more Discord servers?
Add your server