unknown field on BelongsToMany relationship
In my UserResource class, I have a select:
When I attempt to save I get the error:
For some reason it's not automatically applying the pivot table records like the documentation indicates. I have relationships established on both models:
User:
Locations:
Any idea what could be causing it? I do have a
mutateFormDataBeforeSave
method in my EditUser resource, but I'm not touching anything related to this relationship in that method.Solution:Jump to solution
$get('role_id') === 1 will likely fail anyway as $get is a string so you need to either cast it with (int) or 1 = '1'
I am wondering if because you are passing disabled/enabled one of the methods for the relationship is being skipped
Can you move ->relationship() to below disabled?...
14 Replies
That is strange, can you confirm your version of filament please?
v3.0.82
Did you create as
location_user
?yep, location_user is the table name.
Are you casting locations on the user table?
i'm not sure I know what you mean..
which tells me the answer is probably no
Bump...Still hoping to get some help on this. I tried modifying the name of the Select to
location_id
and it just changes the error message. It's still looking for a location_id
directly on the users table, instead of on the pivot.Does this happen when the field is disabled or not disabled
interesting! if I comment out the
->disabled()
line, it works fine..Is the field disabled when it fails to work
no, it's not. That's what doesn't make sense. The record I'm working with doesn't have a role_id === 1, which is the disabled criteria, so it's enabled..
Solution
$get('role_id') === 1 will likely fail anyway as $get is a string so you need to either cast it with (int) or 1 = '1'
I am wondering if because you are passing disabled/enabled one of the methods for the relationship is being skipped
Can you move ->relationship() to below disabled?
ok that works...I didn't realize that order matters on these declarations.
thank you!
Yeah it can do depending on the complexity of the function. Glad to have helped!