© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
12 replies
AngryTestie

Insert Data in Pivot Table

I have 2 tables companies and users with many to many relationship, now I want to add data in pivot table when I'm creating new user how can I do that?Please help
Solution
protected function afterCreate(): void
{
    //companies that you want to attach
    $companies = [1,2,3..];
    
    //use sync or attach to attach the companies
    $this->record->companies()->sync($companies);
}
protected function afterCreate(): void
{
    //companies that you want to attach
    $companies = [1,2,3..];
    
    //use sync or attach to attach the companies
    $this->record->companies()->sync($companies);
}
Jump to solution
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 to a pivot table in table CreateAction?
FilamentFFilament / ❓┊help
2y ago
Pivot data in model/resource table
FilamentFFilament / ❓┊help
2y ago
save repeater data in pivot table
FilamentFFilament / ❓┊help
2y ago
Update data on pivot table
FilamentFFilament / ❓┊help
2y ago