© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
3 replies
Clement

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 ..

                    }),
            ])
                \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();
                    }),
                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
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Loading data from a relationship in a form
FilamentFFilament / ❓┊help
3y ago
Fill form in CreateAction
FilamentFFilament / ❓┊help
7mo ago
createAction inside form section
FilamentFFilament / ❓┊help
3y ago
Nested relationship form data not loading
FilamentFFilament / ❓┊help
3mo ago