© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
Nuekrato

Form: Adding user-defined pivot data to belongsToMany relationship

I have a form like this:
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                CheckboxList::make('allowedTargets')
                    ->disabledOn('edit')
                    ->relationship(name: 'allowedTargets', titleAttribute: 'name')
                    ->pivotData([
                        TextInput::make('allowed_file_extensions')
                            ->label('Allowed File Extensions')
                            ->required(),
                    ])              
            ]);
    }
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                CheckboxList::make('allowedTargets')
                    ->disabledOn('edit')
                    ->relationship(name: 'allowedTargets', titleAttribute: 'name')
                    ->pivotData([
                        TextInput::make('allowed_file_extensions')
                            ->label('Allowed File Extensions')
                            ->required(),
                    ])              
            ]);
    }


allowedTargets
allowedTargets
is a many-to-many-relationship of my Model. Each target has a pivot column
allowed_file_extensions
allowed_file_extensions
which accepts an array of file extensions as strings.

Using a
TextInput
TextInput
inside the
pivotData()
pivotData()
-method is not doing anything. But it is also not documented and was just an example what I already tried. I want the user be able to add allowed_file_extensions as pivot data on the create page of my Model. So he is able to create the parent model directly with the relationship and the specific pivot data. Is that possible?

I also tried it using a RelationManager but it seems like RelationManagers don't show up on the resource create page.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Relationship belongstoMany
FilamentFFilament / ❓┊help
3y ago
relationshipmanager for belongsToMany relationship with pivot table tries to insert into wrong table
FilamentFFilament / ❓┊help
3y ago
Adding BelongsToMany that includes another BelongsToMany relation to a form
FilamentFFilament / ❓┊help
3y ago
Form field in relationship to pivot table
FilamentFFilament / ❓┊help
3y ago