© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
25 replies
Masea

relationshipmanager for belongsToMany relationship with pivot table tries to insert into wrong table

Hey guys might there be any reason that a relation manager tries to insert into the relation table instead of the pivot table?

I currently have usersrelationmanager that is tied to courseresource. my course and users do have many-to-many relationship with a pivot table. inside usersrelationmanager, i have my relationship set to 'users', but when i try to add a new student for a course, it tries to insert an item to the users table...
class UsersRelationManager extends RelationManager
{
    protected static string $relationship = 'users';

    protected static ?string $modelLabel = 'Student';

    protected static ?string $title = 'Enroll Students';

    protected static ?string $recordTitleAttribute = 'id';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('user_id')
                    ->label('Student')
                    ->required()
                    ->options(function (RelationManager $livewire): array {
                        // code to get the users
                    })
                    ->searchable(),
            ]);
    }
class UsersRelationManager extends RelationManager
{
    protected static string $relationship = 'users';

    protected static ?string $modelLabel = 'Student';

    protected static ?string $title = 'Enroll Students';

    protected static ?string $recordTitleAttribute = 'id';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('user_id')
                    ->label('Student')
                    ->required()
                    ->options(function (RelationManager $livewire): array {
                        // code to get the users
                    })
                    ->searchable(),
            ]);
    }


when i try to create a new entry, the realtionshipmanager tries to insert into the users table instead of user_courses table
image.png
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
Relationship with pivot
FilamentFFilament / ❓┊help
3y ago
Relationship belongstoMany
FilamentFFilament / ❓┊help
3y ago
Form: Adding user-defined pivot data to belongsToMany relationship
FilamentFFilament / ❓┊help
2y ago