© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago
Alisher

Select filter attribute name by relation

I have an form select like that
Forms\Components\Select::make('teachers')
  ->label('Teachers')
  ->relationship('teachers')
  ->multiple()
  ->preload()
  ->searchable()
  ->required()
  ->options(
      Teacher::with('user')->get()->pluck('user.name', 'id')->toArray()
  )
Forms\Components\Select::make('teachers')
  ->label('Teachers')
  ->relationship('teachers')
  ->multiple()
  ->preload()
  ->searchable()
  ->required()
  ->options(
      Teacher::with('user')->get()->pluck('user.name', 'id')->toArray()
  )

So Teacher has relation user and I need to get label from user.name

sho I wrote filter like that
Tables\Filters\SelectFilter::make('teachers')
    ->label('Filter by Teacher')
    ->relationship('teachers', 'user.name')
    ->multiple()
    ->preload()
    ->options(fn () => Teacher::with('user')->get()->pluck('user.name', 'id')->toArray())
Tables\Filters\SelectFilter::make('teachers')
    ->label('Filter by Teacher')
    ->relationship('teachers', 'user.name')
    ->multiple()
    ->preload()
    ->options(fn () => Teacher::with('user')->get()->pluck('user.name', 'id')->toArray())


for SelectFilter relationship 2nd param is required and if is not working with relations.
SQLSTATE[HY000]: General error: 1 no such column: user.name (Connection: sqlite, SQL: select distinct "teachers".* from "teachers" left join "speaking_club_teacher" on "teachers"."id" = "speaking_club_teacher"."teacher_id" order by "user"."name" asc)
SQLSTATE[HY000]: General error: 1 no such column: user.name (Connection: sqlite, SQL: select distinct "teachers".* from "teachers" left join "speaking_club_teacher" on "teachers"."id" = "speaking_club_teacher"."teacher_id" order by "user"."name" asc)
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Select Filter with relation
FilamentFFilament / ❓┊help
3y ago
Issue with search on relation & attribute as select name.
FilamentFFilament / ❓┊help
3y ago
Select filter grouping options in relation filter
FilamentFFilament / ❓┊help
3y ago
How to Filter by virtual attribute.
FilamentFFilament / ❓┊help
2y ago