Duplicating record before using inside of editOptionForm.

Hi all,

I would like to duplicate a record before opening it in the modal and editing it using the editOptionForm.
I have been playing around with all the various lifecyclehooks of the editOptionAction -> $action, but without any success at the moment.

I can't seem to find how to pass the newly created record to the Component of the Edit action / form?

Current code (not working):
                ->editOptionForm(FinancialCalculation::form())
                ->editOptionAction(function(Forms\Components\Actions\Action $action, Forms\Components\Select $component, $livewire) {
                    $form_data = $component->getSelectedRecord()?->attributesToArray();

                    if (is_array($form_data)) {
                        $form_data['is_hidden'] = 1;
                        $form_data['is_disabled'] = 1;

                        $action->fillForm(function(Forms\Components\Select $component) use ($form_data) {
                            $record = $component->getSelectedRecord()?->replicate();
                            return $record->attributesToArray();
                        });
                    }

                    return $action->slideOver();
                })


Anyone have any ideas?

Thanks!
Was this page helpful?