FilamentF
Filament16mo ago
Selva

Get the parent id inside child repeater form

I have a nested form using repeater like, main form -> child repeater form -> grandchild repeater form.
Here I need to take the id of main form and insert into grandchild table as main_form_id. I have tried few solutions but not working, This is my form,
return $form
            ->schema([
                // Main form
                Forms\Components\TextInput::make('name')->required()->maxLength(255),

                // child form
                Forms\Components\Repeater::make('groups')->relationship()->schema([
                    Forms\Components\TextInput::make('name')->required(),

                    // grand child form
                    Forms\Components\Repeater::make('requests')->relationship()->schema([
                        Forms\Components\TextInput::make('name')->required(),
                    ])->mutateRelationshipDataBeforeCreateUsing(function (array $data, Get $get) {
                        // $data['project_id'] = $get('../../id');
                        // dd($get());
                        // dd($data);
                        return $data;
                    }),
                ])
            ]);
Was this page helpful?