© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
18 replies
Jon Mason

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()
 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" ],
...
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);
    }
public function locations(): BelongsToMany
    {
        return $this->belongsToMany(Location::class);
    }


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


Any idea what could be causing it? I do have a
mutateFormDataBeforeSave
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?
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Relationship belongstoMany
FilamentFFilament / ❓┊help
3y ago
Scoping belongsToMany relationship?
FilamentFFilament / ❓┊help
3y ago
Preload BelongsToMany relationship on Edit Page
FilamentFFilament / ❓┊help
3y ago
BelongsToMany relationship in Repeater
FilamentFFilament / ❓┊help
3y ago