FilamentF
Filament15mo ago
Bruno

Table Repeater in modalContent

I'm having trouble persisting the data from my modal's table repeater after creating my resource.
CreateCar. many-to-many relationship
 public function getFormActions(): array
    { return [ ...parent::getFormActions(),
                  Action::make('add example')
                    ->modalContent(fn() => view('modal'))
                    ->modalCancelAction(false)
                    ->modalSubmitAction(false)
            ];}

modal.blade:
<div> @livewire('add-example-modal') </div>


Class AddExampleModal
class AddExampleModal extends Component implements HasForms, HasActions
{
    public ?array $data = [];
    public Test $test;

    public function mount(Test $test): void
    {
        $this->test = $test;
        $this->form->fill($test->toArray());
        $testIds = session('selected_test_ids', []);
        session()->forget('selected_test_ids');
    }

    protected function form(Form $form): Form
    {
        return $form
            ->schema([
                TableRepeater::make('testes')
                    ->headers([
                        Header::make(' ')->width('700px'),
                    ])
                    ->schema([
                        Select::make('test_id')
                            ->getSearchResultsUsing(function (string $search) {
                                return Test::query()
                                   \\\
                                    });    
                    ])
            ->statePath('data')
            ->model(Test::class);
    }
    public function create(): void
    {   $test = Test::create($this->form->getState());
        $this->form->model($test)->saveRelationships(); }

    public function confirmAction(): Action
    {
        return Action::make('confirm')
            ->action(function () {
                $data = $this->form->getState();
                session(['selected_tests' => array_column($data['tests'], 'test_id')]);
            });}}
Was this page helpful?