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...
when i try to create a new entry, the realtionshipmanager tries to insert into the users table instead of user_courses table

22 Replies
Here are how my relationships look like for both User and Course models:


Can you share the
table()
method?
Try
AttachAction
instead if CreateAction
Alright. But after i change it to attachaction my select options come empty. Any idea why? This is how it looks like atm:

Probably this https://filamentphp.com/docs/2.x/admin/resources/relation-managers#attaching-with-pivot-attributes
Filament
Relation managers - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
It gives me this error when i try to attach an user

Here's my attachaction:

Instead of
user_id
your custom select, use recordId
Thanks that works!
One last issue though, i cannot see users' name on the table with this:

even though my UserCourse class has user relation
Hmm, not sure... is
fullName
a column on the users table?it is an attribute for the User class but it doesn't matter because i can't get the 'name' either which is a column. i can get user_id here though
looks like this gets info from the user_courses table
Yeah probably, can you try
->formatStateUsing(fn ($record) => dd($record))
on the column?It gets me this... insteresting, it is the 'users' table!

i don't get it

this works
So this should work
->formatStateUsing(fn ($record) => $record->fullName)
Lol yes, even betteri just removed the 'user.' part 😄
alright, thank you so much this really helped me a lot!
You're welcome 🙌