Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ismaail's avatar

[Filament] Get Selected names (not just values) in the Filter indicateUsing

from the example in Filament documentation.

->filters([
    Tables\Filters\SelectFilter::make('location')
        ->form([
            Forms\Components\Select::make('city_id')
                ->options([1 => 'City A',  2 => 'City B'])
         ])
         ->indicateUsing(function(array $data, array $state) {
             /* 
                 Selected City in the Filter is "City A"
                 $data:  array: ["city_id" => "1"]
                 $state: array:["city_id" => "1"]
             */
         })
])

I can get the selected values with $data and $state variables.

But what I want is the name of the selected option: City A or City B

is there a way to get it without doing a query to database City::find(...) ?

0 likes
5 replies
ismaail's avatar

kinda hacky solution:

->indicateUsing(function (SelectFilter $filter, array $state): array {
    $forms = $filter->getFormSchema();
    $cityId = $state['city'];

    if ($cityId) {
        $options = $forms[0]->getOptions();
        $indicators['city'] = "City Name: $options[$cityId]";
    }

    return [];
}


revmitcz's avatar

I don't know if you need to show multiple cities, but if you only need one this is what I came up with for showing the parent category of a sub-category search :

->indicateUsing(function (array $data): ?string {
	if (!$data['parent_id']) {
		return null;
	}

	return 'Main Category : ' . Category::find([$data['parent_id']])->pluck('name')->first();
})

Please or to participate in this conversation.