© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•13mo ago•
4 replies
Martin Oscar

SelectFilter->getOptionLabelFromRecordUsing

SelectFilter::make('event')
    ->options(fn (Table $table) => $table->getQuery()->pluck('event', 'event')->unique()->sort())
    ->searchable()
    ->preload(),
SelectFilter::make('user')
    ->options(fn (Table $table) => $table->getQuery()->pluck('actor_id', 'actor_id')->unique()->sort())
    ->getOptionLabelFromRecordUsing(function (int $actor) {
        $user = User::query()->where('id', $actor)?->username;
        if (!$user instanceof User) {
            return 'System';
        }

        return $user->username;
    })
    ->searchable()
    ->preload(),
SelectFilter::make('event')
    ->options(fn (Table $table) => $table->getQuery()->pluck('event', 'event')->unique()->sort())
    ->searchable()
    ->preload(),
SelectFilter::make('user')
    ->options(fn (Table $table) => $table->getQuery()->pluck('actor_id', 'actor_id')->unique()->sort())
    ->getOptionLabelFromRecordUsing(function (int $actor) {
        $user = User::query()->where('id', $actor)?->username;
        if (!$user instanceof User) {
            return 'System';
        }

        return $user->username;
    })
    ->searchable()
    ->preload(),

The label isn't applied either

I even tried to dd() in
getOptionLabelFromRecordUsing()
getOptionLabelFromRecordUsing()
but it doesn't get called at all
image.png
image.png
Solution
Likely because your code is wrong. $actor won't exist...

Why not do:

SelectFilter::make('user')
    ->relationship('user', 'username')
    ->searchable()
    ->preload(),
SelectFilter::make('user')
    ->relationship('user', 'username')
    ->searchable()
    ->preload(),


Providing the model of the resource has the user relationship?
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

getOptionLabelFromRecordUsing GetRelation
FilamentFFilament / ❓┊help
3y ago
what does the same as "getOptionLabelFromRecordUsing" in Select Input in SelectFilter ?
FilamentFFilament / ❓┊help
3y ago
Table SelectFilter
FilamentFFilament / ❓┊help
9mo ago
SelectFilter ordering
FilamentFFilament / ❓┊help
11mo ago