© 2026 Hedgehog Software, LLC

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

Insert data to a pivot table in table CreateAction?

I have Gem Model and Gem has many Sizes and each size have a price. Size can be belongs to many gems. So i create and pivot table. I added a repeater to set the sizes and price. But Gem creation gives me an error. this is my action and form ===>

Repeater::make('sizes')
->relationship('sizes')
->schema([
  Select::make('size_id')
  ->label('Size')
  ->options(Size::all()->pluck('size', 'id'))
  ->searchable()->preload()
  ->required()->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('price')->suffix('$')->required()->numeric()
->inputMode('decimal'),
])->columns(2)->columnSpanFull()->minItems(1),


public function sizes(): BelongsToMany
 {
return $this->belongsToMany(Size::class, 'gem_sizes', 'gem_id', 'size_id')->withPivot('price')->withTimestamps();
  }
Repeater::make('sizes')
->relationship('sizes')
->schema([
  Select::make('size_id')
  ->label('Size')
  ->options(Size::all()->pluck('size', 'id'))
  ->searchable()->preload()
  ->required()->disableOptionsWhenSelectedInSiblingRepeaterItems(),
TextInput::make('price')->suffix('$')->required()->numeric()
->inputMode('decimal'),
])->columns(2)->columnSpanFull()->minItems(1),


public function sizes(): BelongsToMany
 {
return $this->belongsToMany(Size::class, 'gem_sizes', 'gem_id', 'size_id')->withPivot('price')->withTimestamps();
  }
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

Insert Data in Pivot Table
FilamentFFilament / ❓┊help
3y ago
Add value to field in pivot table in CreateAction
FilamentFFilament / ❓┊help
3y ago
Is a relationship manager required to insert/update pivot table data?
FilamentFFilament / ❓┊help
2y ago
Storing repeater data in a pivot table
FilamentFFilament / ❓┊help
3y ago