unknown field on BelongsToMany relationship

In my UserResource class, I have a select:

 Select::make('locations')
                        ->multiple()
                        ->relationship('locations', 'name')
                        ->disabled(fn (Get $get) => $get('role_id') === 1)
                        ->preload()
                        ->searchable()


When I attempt to save I get the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'locations' in 'field list'
update
  `users`
SET
  `phone` =,
  `is_active` = 1,
  `locations` = [ "25" ],
...


For some reason it's not automatically applying the pivot table records like the documentation indicates. I have relationships established on both models:

User:
public function locations(): BelongsToMany
    {
        return $this->belongsToMany(Location::class);
    }


Locations:
    public function users(): BelongsToMany
    {
        return $this->belongsToMany(User::class);
    }


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
$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?
Was this page helpful?