Can't receive relationship data on a form createAction

Hi

I have a small problem but terrible to investigate on it ..

I have this code on my headerActions of my table:
                \Filament\Tables\Actions\CreateAction::make('Create Workspace')
                    ->label('Create Workspace')
                    ->modalDescription('Create a new workspace for your organization')
                    ->form([
                        Grid::make()
                            ->columns(3)
                            ->schema($this->workspaceSchema()),
                    ])
                    ->model(TeamWorkSpace::class)
                    ->using(function (TeamWorkSpace $workspace,   array $data): void {
                        $data['team_id'] = $this->team->id;

                        $workspace->fill(collect($data)->only(['name', 'team_id', 'available_space', 'slug'])->toArray())->save();
                        $workspace->metiers()->sync($data['metiers']);
                        // $data['metiers'] is empty ..

                    }),
            ])

I also have my workspaceSchema (for my forms), Everything work to create "TeamWorkspace" also when I use the select multiple to create a "metiers" (BelongsToMany relation of TeamWorkspace) I don't have any "metiers" value stored in my $data ...
Also when I edit TeamWorkspace with the following code it works perfectly:
                EditAction::make('Edit Workspace')
                    ->form([
                        Grid::make()
                            ->columns(3)
                            ->schema($this->workspaceSchema()),
                    ])
                    ->using(function (TeamWorkSpace $workspace, array $data): void {
                        $data['team_id'] = $this->team->id;

                        $workspace->fill(collect($data)->only(['name', 'team_id', 'available_space', 'slug'])->toArray())->save();
                    }),

I understand that it works because TeamWorkspace is already created .. But how to in CreateAction
Was this page helpful?