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(),

The label isn't applied either

I even tried to dd() in 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(),


Providing the model of the resource has the user relationship?
Was this page helpful?