Filament PHP Table: field list is ambiguous
When adding a search to a Filament table, you might come across an error like this:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'email' in field list is ambiguous.
The issue arises from joining two or more tables with the same column name as the one you are attempting to search. The fix is to pass the column and table name into the ->searchable()
function:
// Example Join
Users::query()
->join('contacts', 'contacts.user_id', '=', 'users.id');
// TextColumn is searchable on contacts when both tables have the email column
Tables\Columns\TextColumn::make('email')->searchable(['contacts.email'])->sortable(),